Part Number Hot Search : 
220CA 100391 2508CH CMHZ4103 1C101 3KP200C 705MN NJU26
Product Description
Full Text Search
 

To Download ATA5771 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  general features ? atmel ? avr ? microcontroller and rf transmi tter pll in a single qfn24 5mm 5mm package (pitch 0.65 mm) ? operating frequency ranges 310mhz to 350mhz, 429mhz to 439mhz and 868mhz to 928mhz ? temperature range ?40c to +85c ? supply voltage 2.0v to 3.6v allowing usage of single li-cell power supply ? low power consumption ? active mode: typical 9.8ma at 3.0v and 4mhz microcontroller-clock ? power-down mode: typical 200na at 3.0v ? modulation scheme ask/fsk ? integrated pll loop filter ? output power of 8dbm at 315mhz / 7.5dbm at 433.92 mhz / 5.5dbm at 868.3mhz ? easy to design-in due to ex cellent isolation of the pll from the pa and power supply ? single-ended antenna output with high efficient power amplifier ? very robust esd protection: hbm 2500v, mm100v, cdm 1000v ? high performance, low power avr 8-bit microcontroller ? advanced risc architecture ? non-volatile program and data memories ? 4kbytes of in-system progra mmable program memory flash ? 256bytes in-system programmable eeprom ? 256bytes internal sram ? programming lock for self -programming flash program and eeprom data security ? peripheral features ? two timer/counter, 8- and 16-bit coun ters with two pwm channels on both ? 10-bit adc ? on-chip analog comparator ? programmable watchdog timer with separate on-chip oscillator ? universal serial interface (usi) ? special microcontroller features ? debugwire on-chip debug system ? in-system programmable via spi port ? external and internal interrupt sources ? pin change interrupt on 12 pins ? enhanced power-on reset circuit ? programmable brown-out detection circuit ? internal calibrated oscillator ? on-chip temperature sensor ? 12 programmable i/o lines uhf ask/fsk transmitter with the atmel avr microcontroller atmel ATA5771/73/74 9137e?rke?12/10
2 9137e?rke?12/10 atmel ATA5771/73/74 1. general description the atmel ? ATA5771/73/74 is a highly flexible programmable transmitter containing the atmel avr ? microcontroller atmel attiny44v and the uhf pll transmitters in a small qfn24 5mm 5mm package. this device is a member of a transmitter family covering several oper- ating frequency ranges, which has been specifically developed for the demands of rf low-cost data transmission syst ems with data rates up to 32kb it/s using ask or fsk modula- tion. its primary applications are in the application of remote keyless-entry (rke), passive entry go (peg) system and remote start. the ATA5771 is designed for 868mhz application, whereas ata5773 for 315mhz application and ata5774 for 434mhz application. figure 1-1. ask system block diagram uhf a s k/f s k remote control receiver uhf a s k/f s k remote control tr a n s mitter atmel ata577x antenn a loop antenn a v s v s 1 to 6 micro- controller demod vcc_rf gnd_rf pa_enable enable control xto pll vco lna xto pa vco f/4 pll power u p/down ant1 ant2 pxy s 1 s 1 s 1 pxy pxy pxy pxy pxy pxy vdd gnd pxy pxy pxy pxy pxy v s clk
3 9137e?rke?12/10 atmel ATA5771/73/74 figure 1-2. fsk system block diagram uhf a s k/f s k remote control receiver uhf a s k/f s k remote control tr a n s mitter atmel ata577x antenn a loop antenn a v s v s 1 to 6 micro- controller demod vcc_rf gnd_rf pa_enable enable control xto pll vco lna xto pa vco f/4 pll power u p/down ant1 ant2 pxy s 1 s 1 s 1 pxy pxy pxy pxy pxy pxy vdd gnd pxy pxy pxy pxy pxy clk v s
4 9137e?rke?12/10 atmel ATA5771/73/74 2. pin configuration figure 2-1. pinning qfn24 5mm 5mm pb 3 /re s et pb2 pa 7 pb1 pb0 vcc pa 3 /t0 pa4/u s ck pa5/mi s o pa 2 pa 1 pa 0 v s _rf xtal gnd gnd_rf enable gnd ant2 ant1 gnd pa_enable clk pa6/mo s i 24 4 3 6 5 2 1 15 16 1 3 14 17 1 8 2 3 22 21 20 19 7 8 9101112 table 2-1. pin description pin symbol function 1 vcc microcontroller supply voltage 2 pb0 port b is a 4-bit bi-directional i/o port with internal pull-up resistor 3 pb1 port b is a 4-bit bi-directional i/o port with internal pull-up resistor 4 pb3/reset port b is a 4-bit bi-directional i/o port with internal pull-up resistor/reset input 5 pb2 port b is a 4-bit bi-directional i/o port with internal pull-up resistor 6 pa7 port a is a 4-bit bi-directional i/o port with internal pull-up resistor 7 pa6 / mosi port a is a 4-bit bi-directional i/o port with internal pull-up resistor 8 clk clock output signal for microcontroller. the clock output frequency is set by the crystal to fxtal/4 9 pa_enable switches on power amplifier. used for ask modulation 10 ant2 emitter of antenna output stage 11 ant1 open collector antenna output 12 gnd ground 13 pa5/miso port a is a 4-bit bi-directional i/o port with internal pull-up resistor 14 pa4/sck port a is a 4-bit bi-directional i/o port with internal pull-up resistor 15 pa3/t0 port a is a 4-bit bi-directional i/o port with internal pull-up resistor 16 pa2 port a is a 4-bit bi-directional i/o port with internal pull-up resistor 17 pa1 port a is a 4-bit bi-directional i/o port with internal pull-up resistor 18 pa0 port a is a 4-bit bi-directional i/o port with internal pull-up resistor 19 gnd microcontroller ground 20 xtal connection for crystal 21 vs_rf transmitter supply voltage 22 gnd_rf transmitter ground 23 enable enable input 24 gnd ground gnd ground/backplane (exposed die pad)
5 9137e?rke?12/10 atmel ATA5771/73/74 2.1 pin configuration of rf pins table 2-2. pin description pin symbol function configuration 8clk clock output signal for microcontroller. the clock output frequency is set by the crystal to f xtal /4. 9 pa_enable switches on power amplifier. used for ask modulation. 10 11 ant2 ant1 emitter of antenna output stage. open collector antenna output. 20 xtal connection for crystal. 100 100 clk vs 50 k 20 a u ref = 1.1v pa_enable ant1 ant2 1.5 k 1.2 k 182 a xtal vs vs
6 9137e?rke?12/10 atmel ATA5771/73/74 21 vs supply voltage see esd protection circuitry (see figure 5-1 on page 181 ). 22 gnd ground see esd protection circuitry (see figure 5-1 on page 181 ). 23 enable enable input table 2-2. pin description (continued) pin symbol function configuration 200 k enable
7 9137e?rke?12/10 atmel ATA5771/73/74 3. functional description figure 1-1 on page 2 and figure 1-2 on page 3 show the interconnections between the micro- controller and the rf part for a typical application. in the recommended application circuits the clock output of the rf transmitter is connected to the microcontroller in order to be able to generate data rate with tolerance lower than 3%. the transmitter?s crystal oscillator (xto), phase locked loop (pll) and clock generatio n are started using pin enable. the power amplifier (pa) is activated using the connecti on to the pin pa_enable. the fsk modulation is performed due to pulling of the crystal load capacitance for th is purpose the microcontroller out put port together with an external switch applies this modulation technique. for the ask modulation the power amplifier will be switched on and of by modulating the pa_enable pin due to the data. to wake up the system from standby mode at le ast one event is r equired, which will be performed by pushing tone button. after this event the microcontroller starts up with the inter- nal rc oscillator. for the tx op eration the user softwa re must additionally control just 2 pins, the pin enable and pin pa_enable. in case of the fsk modulation one additional connec- tion from microcontroller is nec essary to perform the pulling of the crystal load capacitance. if enable and pa_enable are set to low the transmitter is in standby mode with the suit- able mode setting of the mi crocontroller (mcu) the powe r consumption will be reduced. if enable is set to high and pa_enable to low, the xto, pll, and the clock driver of the rf transmitter are activated and the vco frequency is 32 times the xto frequency. the atmel ATA5771 and atmel ata5774 require typically shorter than 1 ms until the pll is locked and the transmitter?s clock output is stable, while the atmel ata5773 requires time shorter than 3 ms for this progress. if both enable and pa_enable ar e set to high the whole rf transmitter (xto, pll, clock driver and power amplifier) is activated. the ask modulation is achieved by switching on and off the power amplifier via pin pa_enable. the fsk modulation is performed by pulling the crystal load capa citor which will ch ange the reference frequency of the pll due to the data. the microcontroller modulates the load capacitance of the crystal using an external switch. a mos transistor with a low parasitic capacitance is recommended to be used for this purpose. during the fsk modulation is the pa_enable pin set to high. to generate the data for the telegram the intern al rc oscillator of the microcontroller is not accurate enough because this will be affected by ambient temp erature and operating voltage. to reduce the variation of the data rate lower than 3% the clock frequency generated by the rf transmitter should be used as a reference. the mcu has to wait at least longer than 3 ms for ata5773 after setting enable to high, before the clock output from the rf transmitter can be used. for ATA5771 and ata5774 the mcu must wait longer than 1 ms until the clock output is stable. the clock output with the crysta l tolerance is connected to the timer0 of the mcu. this timer clocks the usi to generate the data rate. in the two serial synchronous data transfer modes will be provided by usi. this will be pass out with different physical i/o ports, two wire mode is used for ask and the three wire mode for fsk.
8 9137e?rke?12/10 atmel ATA5771/73/74 3.1 frequency generation in atmel ata5773 and atmel ata5774 the vco is locked to 32 times crystal frequency hence the following crystal is needed ? 9.8438mhz for 315mhz application ? 13.56mhz for 433.92mhz application the vco of ATA5771 is locked to 64 times crystal frequency therefore the necessary crystal frequency is ? 13.5672mhz for 868.3mhz application ? 14.2969mhz for 915mhz application due to the high integration the pll and vco peripheral elements are integrated. the xto is a series resonance oscillator that only one capacitor together with a crystal con- nected in series to gnd are needed as external elements. until the pll and clock output is stable the following time can be expected ? 3ms for ata5773 ? 1ms for ATA5771 and ata5774 therefore, a time delay of 3 ms for ata5773 and 1 ms for ATA5771/74 between activa- tion of pin enable and switching on the pin pa_enable must be implemented in the software. 3.2 ask transmission the ask modulation will performed by switching th e power amplifier on and of due to the data to be transmitted. the transmitter?s xto and pll are activated by setting the pin enable to high. between the activation of the pin en able and the pin pa_enable minimum 3 ms time delay must be taken into account for the application with ata5773, whereas a minimum 1 ms time delay for an application using ATA5771 or ata5774. after the mentioned time delay the generated clock frequency by the rf transmitter can be used as reference for the data generation of the microcontroller block. 3.3 fsk transmission the transmitter?s xto and pll are activated by setting the pin enable to high. like the ask transmission a defined time delay must be taken into account between the activation of the pin enable and the pin pa_enable. after this time delay the clock frequency can be used as reference for the data rate generati on and the data transmission using fsk modula- tion is ready. for this purpose an additional c apacitor to the crystal?s load capacitor will be switched between the high impedance and ground due to the data rate. thus the reference frequency, which is crys tal frequency, of the rf transmitter will be modulated. this results also in the transmitted spectrum. it is important that the switching element must have a defined low parasitic capacitance. the accuracy of the frequency deviation with xt al pulling method is about 25% when the following tolerances are considered.
9 9137e?rke?12/10 atmel ATA5771/73/74 figure 3-1. tolerances of frequency modulation using c 4 =8.2pf5%, c 5 = 10 pf 5%, a switch port with c switch = 3 pf 10%, stray capaci- tances on each side of the crystal of c stray1 =c stray2 = 1 pf 10%, a parallel capacitance of the crystal of c 0 = 3.2 pf 10% and a crystal with c m = 13 ff 10%, results in a typical fsk devia- tion of 21.5 khz with worst case tolerances of 16.25 khz to 28.01 khz. 3.4 clk output rf transmitter generated clock signal based on the devided crystal frequency. this will be available for the microcontroller as reference. the delivered signal is cmos compatible if the load capacitance is lower than 10pf. 3.4.1 clock pulse take-over the clock of the crystal oscilla tor can be used for clocking th e microcontroller, which starts with an integrated rc-oscillator. after the gener ated clock signal of the rf transmitter is sta- ble, the microcontroller will take over the clock signal and use it as reference generating the data rate, so that the message can be transmitted with crystal accuracy. 3.4.2 output matching and power setting the power amplifier is an open-collector output delivering a current pulse, which is nearly independent from the load impedance. thus the delivered output power can be tuned via the load impedance of the antenna and the matching elements. this output configuration enables simple matching to any kind of antenna or to 50 which results in a high power efficiency { =p out /(i s,pa v s ) }. the maximum output power can be achieved at 3v supply voltage when the load impedance is optimized to ? z load = (255 + j192) for the atmel ata5773 with the power efficiency of 40% ? background : the current pulse of the power amplifier is 9ma and the maximum output power is delivered to a resistive load of 400 if the 1.0pf output capacitance of the power amplifier is compensated by the load impedance. and thus the load impedance of z load =400 || j/(2 f 1.0 pf) = (255 + j192) is achieved for the maximum output power of 8dbm. ? z load = (166 + j223) for the atmel ata5774 with the power efficiency of 36% ? background : the current pulse of the power amplifier is 9ma and the maximum output power is delivered to a resistive load of 465 if the 1.0pf output capacitance of the power amplifier is compensated by the load impedance. and thus the load impedance of z load = 465 || j/(2 f 1.0 pf) = (166 + j223) is achieved for the maximum output power of 7.5dbm. r s l m c 4 c m v s xtal crystal equivalent circuit c 0 c 5 c switch c stray1 c stray2
10 9137e?rke?12/10 atmel ATA5771/73/74 ? z load = (166 + j226) for the atmel ATA5771 with the power efficiency of 24% ? background : the current pulse of the power amplifier is 7.7ma and the maximum output power is delivered to a resistive load of 475 if the 0.53pf output capacitance of the power amplifier is compensated by the load impedance. and thus the load impedance of z load = 475 || j/(2 f 0.53 pf) = (166 + j226) is achieved for the maximum output power of 5.5dbm. the load impedance is defined as the impedance seen from the power amplifier (pin ant1 and pin ant2) into the matching network. this large signal load impedance should not be mixed up with the small signal input impedance de livered as input characteristic of rf amplifi- ers and measured from the application into the ic, instead of from the ic into the application. please take note that there must be a low resistive path between the v s and the collector out- put of the pa to deliver the dc current. reduced output power will be achieved by lowering the real parallel part of the load impedance w here the parallel imaginary part should be kept constant. output power measurement can be performed using the circuit shown in figure 3-2 . note that the component values must be changed to compensate for the individual board parasitics until the rf power amplifier has the right load imp edance. in addition, the damping of the cable used to measure the output power must be calibrated out. figure 3-2. output power measurement atmel ATA5771/73/74 l 1 = 47 nh c 2 = 3 . 3 pf c 1 = 1 nf v s r in ant2 ant1 z lopt power meter 50 z = 50
11 9137e?rke?12/10 atmel ATA5771/73/74 4. microcontroller block these data are referred to the data base of microcontroller atmel attiny44v. 4.1 overview the attiny44v is a low-power cmos 8-bi t microcontroller based on the atmel avr ? enhanced risc architecture. by executing powerf ul instructions in a single clock cycle, the attiny44v achieves throughputs approaching 1 m ips per mhz allowing the system designer to optimize power consumption versus processing speed. 4.2 block diagram figure 4-1. block diagram watchdog timer mcu control register timer/ counter0 data dir. reg.port a data register port a programming logic timing and control mcu status register port a drivers pa7-pa0 vcc gnd + - analog comparator 8-bit databus adc isp interface interrupt unit eeprom internal oscillator oscillators calibrated oscillator internal data dir. reg.port b data register port b port b drivers pb3-pb0 program counter stack pointer program flash sram general purpose registers instruction register instruction decoder status register z y x alu control lines timer/ counter1
12 9137e?rke?12/10 atmel ATA5771/73/74 the atmel avr ? core combines a rich instruction set with 32 general purpose working regis- ters. all the 32 registers are directly connected to the arithmetic logic unit (alu), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. the resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional cisc microcontrollers. the atmel attiny44v provides the following f eatures: 4k byte of in-system programmable flash, 256 bytes eeprom, 256 bytes sram, 12 general purpose i/o lines, 32 general pur- pose working registers, a 8-bit timer/counter with two pwm channels, a 16-bit timer/counter with two pwm channels, internal and external interrupts, a 8-channel 10-bit adc, program- mable gain stage (1x, 20x) for 12 differential adc channel pairs, a programmable watchdog timer with internal oscillator, internal calibrated os cillator, and three software selectable power saving modes. the idle mode stops the cpu while allowing the sram, timer/counter, adc, analog comparator, and interrupt system to continue functioning. the power-down mode saves the register contents, disabling all chip functions until the next interrupt or hard- ware reset. the adc noise reduction mode stops the cpu and all i/o modules except adc, to minimize switching noise during adc conversions. in standby mode, the crystal/resonator oscillator is running while the rest of the device is sleeping. this allows very fast start-up com- bined with low power consumption. the device is manufactured using the atmel high density non-volatile memory technology. the on-chip isp flash allows the program memory to be re-programmed in-system through an spi serial interface, by a conventional non-volatile memory programmer or by an on-chip boot code running on the avr core. the attiny44v avr is supported with a full suite of program and system development tools including: c compilers, macro assemblers, program debugger/simulators, in-circuit emula- tors, and evaluation kits. 4.3 automotive quality grade the attiny44v have been developed and manufactured according to the most stringent requirements of the international standard iso-ts-16949 grade 1. this data sheet contains limit values extracted from the results of extensive characterization (temperature and volt- age). the quality and reliability of the attiny 44v have been verified during regular product qualification as per aec-q100. as indicated in the ordering information paragraph, the product is available in only one temper- ature grade. table 4-1. temperature grade identification for automotive products temperature temperature identifier comments -40 ; +125 z full automotive temperature range
13 9137e?rke?12/10 atmel ATA5771/73/74 4.4 pin descriptions 4.4.1 vcc supply voltage. 4.4.2 gnd ground. 4.4.3 port b (pb3...pb0) port b is a 4-bit bi-directional i/o port with internal pull-up resistors (selected for each bit). the port b output buffers have symmetrical drive characteristics with both high sink and source capability except pb3 which has the reset capability. to use pin pb3 as an i/o pin, instead of reset pin, program (?0?) rstdisbl fuse. as inputs, port b pins that are externally pulled low will source current if the pull- up resistors are activated. the port b pins are tri-stated when a reset condition becomes active, even if the clock is not running. port b also serves the functions of various spec ial features of the atmel attiny44v as listed on section 4.14.3 ?alternate port functions? on page 66 . 4.4.4 reset reset input. a low level on this pin for lon ger than the minimum pulse length will generate a reset, even if the clock is not running. the minimum pulse length is given in figure 4-13 on page 46 . shorter pulses are not guaranteed to generate a reset. 4.4.5 port a (pa7...pa0) port a is a 8-bit bi-directional i/o port with internal pull-up resistors (selected for each bit). the port a output buffers have symmetrical drive characteristics with both high sink and source capability. as inputs, port a pi ns that are externally pulled lo w will source current if the pull-up resistors are activated. the port a pins are tri-stated when a reset condition becomes active, even if the clock is not running. port a has an alternate functions as analog inputs for the adc, analog comparator, timer/counter, spi and pin change interrupt as described in section 4.14.3 ?alternate port functions? on page 66 . 4.5 resources a comprehensive set of development tools, drivers and application notes, and datasheets are available for download on http://www.atmel.com/avr. 4.6 about code examples this documentation contains simple code examples that briefly show how to use various parts of the device. these code examples assume th at the part specific header file is included before compilation. be aware that not all c compiler vendors include bit definitions in the header files and interrupt handling in c is compiler dependent. please confirm with the c com- piler documentation for more details. for i/o registers located in extended i/o map, ?in?, ?out?, ?sbis?, ?sbic?, ?cbi?, and ?sbi? instructions must be replaced with instructions that allow access to extended i/o. typically ?lds? and ?sts? combined with ? sbrs?, ?sbrc?, ?sbr?, and ?cbr?.
14 9137e?rke?12/10 atmel ATA5771/73/74 4.7 cpu core 4.7.1 overview this section discusses the atmel avr ? core architecture in general. the main function of the cpu core is to ensure correct program execution. the cpu must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. 4.7.2 architectural overview figure 4-2. block diagram of the atmel avr architecture in order to maximize performance and parallelis m, the avr uses a harvard architecture ? with separate memories and buses for program and data. instructions in the program memory are executed with a single level pipelining. whil e one instruction is being executed, the next instruction is pre-fetched from the program memory. this concept enables instructions to be executed in every clock cycle. the program me mory is in-system reprogrammable flash memory. flash program memory instruction register instruction decoder program counter control lines 32 x 8 general purpose registrers alu status and control i/o lines eeprom data bus 8-bit data sram direct addressing indirect addressing interrupt unit watchdog timer analog comparator timer/counter 0 timer/counter 1 universal serial interface
15 9137e?rke?12/10 atmel ATA5771/73/74 the fast-access register file contains 32 x 8-bit general purpose working registers with a sin- gle clock cycle access time. this allows single-cyc le arithmetic logic un it (alu) operation. in a typical alu operation, two operands are output from the register file, the operation is exe- cuted, and the result is stored back in the register file ? in one clock cycle. six of the 32 registers can be used as three 16-bit indirect address register pointers for data space addressing ? enabling efficient address ca lculations. one of the these address pointers can also be used as an address pointer for look up tables in flash program memory. these added function registers are the 16-bit x-, y-, and z-register, described later in this section. the alu supports arithmetic and logic operations between registers or between a constant and a register. single register operations can also be executed in the alu. after an arithmetic operation, the status register is updated to reflect information about the result of the operation. program flow is provided by conditional and un conditional jump and call instructions, able to directly address the whole address space. most atmel avr ? instructions have a single 16-bit word format. every program memory address contains a 16- or 32-bit instruction. during interrupts and subroutine calls, the return address program counter (pc) is stored on the stack. the stack is effectively allocated in the general data sram, and consequently the stack size is only limited by t he total sram size and the usage of the sram. all user pro- grams must initialize the sp in the reset routine (before subroutines or interrupts are executed). the stack pointer (sp) is read/writ e accessible in the i/o space. the data sram can easily be accessed through the five different addressing modes supported in the avr architecture. the memory spaces in the avr architecture are all linear and regular memory maps. a flexible interrupt module has its control registers in the i/o space with an additional global interrupt enable bit in the status register. all interrupts have a separate interrupt vector in the interrupt vector table. the interrupts have priority in accordance with their interrupt vector position. the lower the interrupt vector address, the higher the priority. the i/o memory space contains 64 addresses for cpu peripheral functions as control regis- ters, spi, and other i/o functions. the i/o memory can be accessed directly, or as the data space locations following those of the register file, 0x20 - 0x5f. 4.7.3 alu ? arithmetic logic unit the high-performance avr alu operates in direct connection with all the 32 general purpose working registers. within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immedi ate are executed. the alu operations are divided into three main categories ? arithmetic, logical, and bit-functions. some implementa- tions of the architecture also provide a pow erful multiplier supporting both signed/unsigned multiplication and fractional format. see the ?instruction set? section for a detailed description. 4.7.4 status register the status register contains information about the result of the most recently executed arith- metic instruction. this information can be used for altering program flow in order to perform conditional operations. note that the status register is updated after all alu operations, as specified in the instruction set reference. this will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. the status register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. this must be handled by software.
16 9137e?rke?12/10 atmel ATA5771/73/74 4.7.4.1 sreg ? avr status register ? bit 7 ? i: global interrupt enable the global interrupt enable bit must be set for the interrupts to be enabled. the individual interrupt enable control is then performed in separate control registers. if the global interrupt enable register is cleared, none of the in terrupts are enabled independent of the individual interrupt enable settings. the i-bit is cleared by hardware after an interrupt has occurred, and is set by the reti instruction to enable subsequent interrupts. the i-bit can also be set and cleared by the application with the sei and cli in structions, as described in the instruction set reference. ? bit 6 ? t: bit copy storage the bit copy instructions bld (bit load) and bst (bit store) use the t-bit as source or des- tination for the operated bit. a bit from a register in the register file can be copied into t by the bst instruction, and a bit in t can be copied into a bit in a register in the register file by the bld instruction. ? bit 5 ? h: half carry flag the half carry flag h indicates a half carry in some arithmetic operations. half carry is use- ful in bcd arithmetic. see the ?instruction set description? for detailed information. ? bit 4 ? s: sign bit, s = n v the s-bit is always an exclusive or between the negative flag n and the two?s complement overflow flag v. see the ?instruction set description? for detailed information. ? bit 3 ? v: two?s complement overflow flag the two?s complement overflow flag v supports two?s complement arithmetics. see the ?instruction set description? for detailed information. ? bit 2 ? n: negative flag the negative flag n indicates a negative result in an arithmetic or logic operation. see the ?instruction set description? for detailed information. ? bit 1 ? z: zero flag the zero flag z indicates a zero result in an arithmetic or logic operation. see the ?instruction set description? for detailed information. ? bit 0 ? c: carry flag the carry flag c indicates a carry in an arithmetic or logic operation. see the ?instruction set description? for de tailed information. bit 76543210 0x3f (0xsf) i t h s v n z c sreg read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
17 9137e?rke?12/10 atmel ATA5771/73/74 4.7.5 general purpose register file the register file is optimized for the atmel ? avr ? enhanced risc instruction set. in order to achieve the required performance and flexibility, the following input/output schemes are sup- ported by the register file: ? one 8-bit output operand and one 8-bit result input ? two 8-bit output operands and one 8-bit result input ? two 8-bit output operands and one 16-bit result input ? one 16-bit output operand and one 16-bit result input figure 4-3 shows the structure of the 32 general purpose working registers in the cpu. figure 4-3. atmel avr cpu general purpose working registers most of the instructions operating on the register file have direct access to all registers, and most of them are single cycle instructions. as shown in figure 4-3 , each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user data space. although not being physically imple- mented as sram locations, this me mory organization pr ovides great flexibility in access of the registers, as the x-, y- and z-pointer registers can be set to index any register in the file. 4.7.5.1 the x-register, y-register, and z-register the registers r26..r31 have some added func tions to their general purpose usage. these registers are 16-bit address pointers for indirect addressing of the data space. the three indi- rect address registers x, y, and z are defined as described in figure 4-4 on page 18 . 70addr. r0 0x00 r1 0x01 r2 0x02 ? r13 0x0d general r14 0x0e purpose r15 0x0f working r16 0x10 registers r17 0x11 ? r26 0x1a x-register low byte r27 0x1b x-register high byte r28 0x1c y-register low byte r29 0x1d y-register high byte r30 0x1e z-register low byte r31 0x1f z-register high byte
18 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-4. the x-, y-, and z-registers in the different addressing modes these address registers have functions as fixed displace- ment, automatic increment, and automatic decrement (see the ?instruction set reference? for details). 4.7.6 stack pointer the stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. the stack pointer register always points to the top of the stack. note that the stack is implemented as growing from higher memory locations to lower memory locations . this implies that a stack push command decreases the stack pointer. the stack pointer points to the data sram stack area where the subroutine and interrupt stacks are located. this stack space in the data sram must be defined by the program before any subroutine calls are executed or in terrupts are enabled. the stack pointer must be set to point above 0x60. the stack pointer is decremented by one when data is pushed onto the stack with the push instruction, and it is decremented by two when the return address is pushed onto the stack with subroutine call or interrupt. the stack pointer is incremented by one when data is popped from the stack with the pop instruction, and it is incremented by two when data is popped from the stack with return from subroutine ret or return from interrupt reti. the atmel avr ? stack pointer is implemented as two 8- bit registers in the i/o space. the number of bits actually used is implementation dependent. note that the data space in some implementations of the avr architecture is so small that only spl is needed. in this case, the sph register will not be present. 4.7.6.1 sph and spl ? stack pointer high and low 15 xh xl 0 x-register 707 0 r27 (0x1b) r26 (0x1a) 15 yh yl 0 y-register 707 0 r29 (0x1d) r28 (0x1c) 15 zh zl 0 z-register 7070 r31 (0x1f) r30 (0x1e) bit 151413121110 9 8 0x3e (0x5e) sp15 sp14 sp13 sp12 sp11 sp10 sp9 sp8 sph 0x3d (0x5d) sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 spl 76543210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000 00000000
19 9137e?rke?12/10 atmel ATA5771/73/74 4.7.7 instruction execution timing this section describes the general access ti ming concepts for instruction execution. the atmel ? avr ? cpu is driven by the cpu clock clk cpu , directly generated from the selected clock source fo r the chip. no internal clock division is used. figure 4-5 shows the parallel instruction fetches and instruction executions enabled by the harvard architecture and the fast access register file concept. this is the basic pipelining concept to obtain up to 1mips per mhz with the corresponding unique results for functions per cost, functions per clocks, and functions per power-unit. figure 4-5. the parallel instruction fetches and instruction executions figure 4-6 shows the internal timing concept for t he register file. in a single clock cycle an alu operation using two register operands is executed, and the result is stored back to the destination register. figure 4-6. single cycle alu operation 4.7.8 reset and interrupt handling the avr provides several different interrupt sources. these interrupts and the separate reset vector each have a separate program vector in the program memory space. all interrupts are assigned individual enable bits which must be written logic one together with the global inter- rupt enable bit in the status register in order to enable the interrupt. the lowest addresses in the program memory space are by default defined as the reset and interrupt vectors. the complete list of vectors is shown in section 4.12 ?interrupts? on page 55 . the list also determines the priority levels of the different interrupts. the lower the address the higher is the priority leve l. reset has the highest priority , and next is int0 ? the external interrupt request 0. clk 1st instruction fetch 1st instruction execute 2nd instruction fetch 2nd instruction execute 3rd instruction fetch 3rd instruction execute 4th instruction fetch t1 t2 t3 t4 cpu total execution time register operands fetch alu operation execute result write back t1 t2 t3 t4 clk cpu
20 9137e?rke?12/10 atmel ATA5771/73/74 when an interrupt occurs, the global interrupt enable i-bit is cleared and all interrupts are dis- abled. the user software can write logic one to the i-bit to enable nested interrupts. all enabled interrupts can then interrupt the current interrupt routine. the i-bit is automatically set when a return from interrupt instruction ? reti ? is executed. there are basically two types of interrupts. the first type is triggered by an event that sets the interrupt flag. for these interrupts, the program counter is vectored to the actual interrupt vector in order to execute the interrupt handling routine, and hardware clears the correspond- ing interrupt flag. interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. if an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the in terrupt flag will be set and reme mbered until the interrupt is enabled, or the flag is cleared by software. similarly, if one or more interrupt conditions occur while the global interrupt enable bit is cleared, the correspond ing interrupt flag(s) will be set and remembered until the global inte rrupt enable bit is set, and will then be executed by order of priority. the second type of interrupts will trigger as long as t he interrupt c ondition is present. these interrupts do not necessarily have interrupt flags. if the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. when the atmel avr ? exits from an interrupt, it will alwa ys return to the main program and execute one more instruction before any pending interrupt is served. note that the status register is not automat ically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. this must be handled by software. when using the cli instruction to disable interrupts, the interrupts will be immediately dis- abled. no interrupt will be executed after the cl i instruction, even if it occurs simultaneously with the cli instruction. the following example shows how this can be used to avoid interrupts during the timed eeprom write sequence. assembly code example in r16, sreg ; store sreg value cli ; disable interrupts during timed sequence sbi eecr, eempe ; start eeprom write sbi eecr, eepe out sreg, r16 ; restore sreg value (i-bit) c code example char csreg; csreg = sreg; /* store sreg value */ /* disable interrupts during timed sequence */ _cli(); eecr |= (1< 21 9137e?rke?12/10 atmel ATA5771/73/74 when using the sei instruction to enable interrupts, the instruction following sei will be exe- cuted before any pending interrupts, as shown in this example. 4.7.8.1 interrupt response time the interrupt execution response for all the enabled atmel ? avr ? interrupts is four clock cycles minimum. after four clock cycles the pr ogram vector address for the actual interrupt handling routine is executed. during this four clock cycle period, the program counter is pushed onto the stack. the vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. if an interrupt occurs during execution of a multi-cycle instruction, this instruction is completed before the interrupt is served. if an interrupt occurs when the mcu is in sleep mode, the interrupt execution response time is increased by four clock cycles. this increase comes in addition to the start-up time from the selected sleep mode. a return from an interrupt handling routine takes four clock cycles. during these four clock cycles, the program counter (two bytes) is popped back from the stack, the stack pointer is incremented by two, and the i-bit in sreg is set. assembly code example sei ; set global interrupt enable sleep ; enter sleep, waiting for interrupt ; note: will enter sleep before any pending ; interrupt(s) c code example _sei(); /* set global interrupt enable */ _sleep(); /* enter sleep, waiting for interrupt */ /* note: will enter sleep before any pending interrupt(s) */
22 9137e?rke?12/10 atmel ATA5771/73/74 4.8 memories this section describes the different memories in the atmel ? attiny44v. the atmel avr ? architecture has two main memory spaces, the data memory and the program memory space. in addition, the atti ny44v features an eepr om memory for data storage. all three memory spaces are linear and regular. 4.8.1 in-system re-programmable flash program memory the attiny44v contains 4k byte on-chip in -system reprogrammable flash memory for pro- gram storage. since all avr instructions are 16 or 32 bits wide, the flash is organized as 2048 x 16. the flash memory has an endurance of at l east 10,000 write/erase cycles. the attiny44v program counter (pc) is 11 bits wide, thus addressing the 2048 program memory locations. section 4.23 ?memory programming? on page 166 contains a detailed description on flash data serial downloading using the spi pins. constant tables can be allocated within the entire program memory address space (see the lpm ? load program memory instruction description). timing diagrams for instruction fetc h and execution are presented in figure 4-7 . figure 4-7. program memory map 4.8.2 sram data memory figure 4-8 on page 23 shows how the attiny44v sram memory is organized. the lower 160 data memory locations address both the register file, the i/o memory and the internal data sram. the first 32 locations address the register file, the next 64 locations the standard i/o memory, and the last 256 locations address the internal data sram. the five different addressing modes for the data memory cover: direct, indirect with displace- ment, indirect, indirect with pre-decrement, and indirect with post-increment. in the register file, registers r26 to r31 feature the indirect addressing pointer registers. the direct addressing reaches the entire data space. the indirect with displacement mode reaches 63 address locations from the base address given by the y- or z-register. when using register indirect addressing modes with automatic pre-decrement and post-incre- ment, the address registers x, y, and z are decremented or incremented. 0x0000 0x07ff pro g ram memory
23 9137e?rke?12/10 atmel ATA5771/73/74 the 32 general purpose working registers, 64 i/o registers, and the 256 bytes of internal data sram in the attiny44v are all accessible through all these addressing modes. the register file is described in section 4.7.5 ?general purpose register file? on page 17 . figure 4-8. data memory map 4.8.2.1 data memory access times this section describes the general access timi ng concepts for internal memory access. the internal data sram access is performed in two clk cpu cycles as described in figure 4-9 . figure 4-9. on-chip data sram access cycles 3 2 regi s ter s 64 i/o regi s ter s intern a l s ram (256 x 8 ) 0x0000 - 0x001f 0x0020 - 0x005f 0x015f 0x0060 data memory clk wr rd data data address address valid t1 t2 t3 compute address read write cpu memory access instruction next instruction
24 9137e?rke?12/10 atmel ATA5771/73/74 4.8.3 eeprom data memory the atmel ? attiny44v contains 256 bytes of data ee prom memory. it is organized as a sep- arate data space, in which single bytes can be read and written. the eeprom has an endurance of at least 100,000 write/erase cycles. the access between the eeprom and the cpu is described in the following, specifyi ng the eeprom address registers, the eeprom data register, and the eeprom control register. for a detailed description of serial data downloading to the eeprom, see section 4.23.6 ?serial downloading? on page 169 . 4.8.3.1 eeprom read/write access the eeprom access registers are accessible in the i/o space. the write access times fo r the eeprom are given in table 4-2 on page 30 . a self-timing func- tion, however, lets the user software detect when the next byte can be written. if the user code contains instructions that write the eeprom , some precautions must be taken. in heavily filtered power supplies, v cc is likely to rise or fall slowly on power-up/down. this causes the device for some period of time to run at a voltage lower than specified as minimum for the clock frequency used. see section 4.8.3.6 ?preventing eeprom corruption? on page 27 for details on how to avoid problems in these situations. in order to prevent unintenti onal eeprom writes, a specific wr ite procedure must be followed. see section 4.8.3.2 ?atomic byte programming? on page 24 and section 4.8.3.3 ?split byte programming? on page 24 for details on this. when the eeprom is read, the cpu is halted for four clock cycl es before the ne xt instruction is executed. when the eeprom is written, the cpu is halted for two clock cycles before the next instruction is executed. 4.8.3.2 atomic byte programming using atomic byte programming is the simplest mode. when writing a byte to the eeprom, the user must write the addres s into the eearl register and da ta into eedr register. if the eepmn bits are zero, writing eepe (within four cycles after eempe is written) will trigger the erase/write operation. both the erase and write cycle are done in one operation and the total programming time is given in table 1. the eepe bit remains set until the erase and write operations are completed. while the device is busy with programming, it is not possible to do any other eeprom operations. 4.8.3.3 split byte programming it is possible to split the erase and write cycle in two different operations. this may be useful if the system requires short access time for some limited period of time (typically if the power supply voltage falls). in order to take advantage of this method, it is required that the locations to be written have been erased before the write operation. but since the erase and write oper- ations are split, it is possible to do the er ase operations when th e system allows doing time-critical operations (t ypically after power-up). 4.8.3.4 erase to erase a byte, the address mu st be written to eear. if the eepmn bits are 0b01, writing the eepe (within four cycles after eempe is written) will trigger the erase operation only (pro- gramming time is given in t able 1). the eepe bit remains set until the erase operation completes. while the devi ce is busy programming, it is not possible to do any other eeprom operations.
25 9137e?rke?12/10 atmel ATA5771/73/74 4.8.3.5 write to write a location, the user must write the address into eear and the data into eedr. if the eepmn bits are 0b10, writing the eepe (within four cycles after eempe is written) will trigger the write operation only (pro gramming time is given in ta ble 1). the eepe bit remains set until the write operation completes. if the location to be written has not been erased before write, the data that is stored must be consid ered as lost. while the device is busy with pro- gramming, it is not possible to do an y other eeprom operations. the calibrated oscillator is used to time the eeprom accesse s. make sure the oscillator fre- quency is within the requirements described in section 4.9.10.1 ?oscillator calibration register ? osccal? on page 39 . the following code examples show one assemb ly and one c function for erase, write, or atomic write of the eeprom. the examples assu me that interrupts ar e controlled (e.g., by disabling interrupts globally ) so that no interrupts will oc cur during execution of these functions.
26 9137e?rke?12/10 atmel ATA5771/73/74 note: the code examples are only valid for the atmel ? attiny44v, using 8-bit addressing mode. assembly code example eeprom_write: ; wait for completion of previous write sbic eecr,eepe rjmp eeprom_write ; set programming mode ldi r16, (0<>eepm0) /* set up address and data registers */ eearl = ucaddress; eedr = ucdata; /* write logical one to eempe */ eecr |= (1< 27 9137e?rke?12/10 atmel ATA5771/73/74 the next code examples show assembly a nd c functions for r eading the eeprom. the examples assume that interrupts are controlled so that no interrupts will occur during execu- tion of these functions. note: the code examples are only valid for the atmel attiny44v, using 8-bit addressing mode. 4.8.3.6 preventing eeprom corruption during periods of low v cc , the eeprom data can be corrupted because the supply voltage is too low for the cpu and the eeprom to operate properly. these issues are the same as for board level systems using eepr om, and the same design so lutions should be applied. an eeprom data corruption can be caused by two situations when the voltage is too low. first, a regular write sequence to the eeprom requires a minimum voltage to operate cor- rectly. secondly, the cpu itself ca n execute instructions incorrectly, if the supply voltage is too low. eeprom data corruption can ea sily be avoided by followin g this design recommendation: keep the atmel ? avr ? reset active (low) during periods of insufficient power supply volt- age. this can be done by enabling the internal brown-out detector (bod). if the detection level of the internal bod does not match the needed detection level, an external low v cc reset protection circuit can be used. if a reset occurs while a write operation is in progress, the write operation will be completed prov ided that the po wer supply voltag e is sufficient. assembly code example eeprom_read: ; wait for completion of previous write sbic eecr,eepe rjmp eeprom_read ; set up address (r17) in address register out eearl, r17 ; start eeprom read by writing eere sbi eecr,eere ; read data from data register in r16,eedr ret c code example unsigned char eeprom_read( unsigned char ucaddress) { /* wait for completion of previous write */ while(eecr & (1< 28 9137e?rke?12/10 atmel ATA5771/73/74 4.8.4 i/o memory the i/o space definition of the atmel ? attiny44v is shown in section 9.1 ?register summary? on page 213 . all attiny44v i/os and peripherals are placed in the i/o space. all i/o locations may be accessed by the ld/lds/ldd and st/sts/std instructions, transferring data between the 32 general purpose working registers and the i/o space. i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using t he sbi and cbi instructions. in these registers, the value of single bits can be checked by using the sbis and sbic instructions. see the instruction set section for more details. when using the i/o specific commands in and out, the i/o addresses 0x00 - 0x3f must be used. when addressing i/o registers as data space using ld and st instructions, 0x20 must be added to these addresses. for compatibility with future devi ces, reserved bits should be wr itten to zero if accessed. reserved i/o memory addresses should never be written. some of the status flags are cleared by writing a logical one to them. note that, unlike most other atmel avr ? microcontrollers, the cb i and sbi instructions will only operate on the spec- ified bit, and can therefore be used on registers containing such status flags. the cbi and sbi instructions work with registers 0x00 to 0x1f only. the i/o and peripherals control registers are explained in later sections. 4.8.4.1 general purpose i/o registers the attiny44v contains three general purpose i/o registers. these registers can be used for storing any information, and they are particularly useful for storing global variables and status flags. general purpose i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using the sbi, cbi, sbis, and sbic instructions.
29 9137e?rke?12/10 atmel ATA5771/73/74 4.8.5 register description 4.8.5.1 eearh ? eeprom address register ? bits 7..1 ? res: reserved bits these bits are reserved bits in the atmel ? attiny44v and will always read as zero. ? bit 0 ? eear8: eeprom address this bit is reserved bit and will always read as zero. the initial value of eear is undefined. a proper value must be written before the eeprom may be accessed. 4.8.5.2 eearl ? eeprom address register ? bits 7..0 ? eear7..0: eeprom address the eeprom address register ? eearl ? sp ecifies the eeprom address. the eeprom data bytes are addressed linearly between 0 and 256. the initial va lue of eear is undefined. a proper value mu st be written before the eeprom may be accessed. 4.8.5.3 eedr ? eeprom data register ? bits 7..0 ? eedr7..0: eeprom data for the eeprom write operation the eedr register contains the data to be written to the eeprom in the address given by the eear register. for the eeprom read op eration, the eedr contains the data read out from the eeprom at the add ress given by eear. 4.8.5.4 eecr ? eeprom control register bit 76543210 0x1f (0x3f) ???????eear8eearh read/write rrrrrrrr/w initial value 0 0 0 0 0 0 0 x bit 76543210 0x1e (0x3e) eear7 eear6 eear5 eear4 eear3 eear2 eear1 eear0 eearl read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value x x x x x x x x bit 76543210 0x1d (0x3d) eedr7 eedr6 eedr5 eedr4 eedr3 eedr2 eedr1 eedr0 eedr read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x1c (0x3c) ? ? eepm1 eepm0 eerie eempe eepe eere eecr read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 x x 0 0 x 0
30 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 7 ? res: reserved bit this bit is reserved for future us e and will always read as 0 in atmel ? attiny44v. for compati- bility with future atmel avr ? devices, always write this bit to zero. after reading, mask out this bit. ? bit 6 ? res: reserved bit this bit is reserved in the atti ny44v and will always read as zero. ? bits 5, 4 ? eepm1 and eepm0: eeprom mode bits the eeprom programming mode bits setting defines which programming action that will be triggered when writing eepe. it is possible to program data in one atomic operation (erase the old value and program the new value) or to split the erase and write operations in two differ- ent operations. the programming times for the different modes are shown in table 4-2 . while eepe is set, any write to eepmn will be ignored. during reset, the eepmn bits will be reset to 0b00 unless the eeprom is busy programming. ? bit 3 ? eerie: eeprom ready interrupt enable writing eerie to one enables the eeprom ready interrupt if the i- bit in sreg is set. writing eerie to zero disables the interrupt. the eeprom ready interrupt generates a constant interrupt when non-volatile me mory is ready for programming. ? bit 2 ? eempe: eeprom master program enable the eempe bit determines whether writing eepe to o ne will have effect or not. when eempe is set, setting eepe within four clock cycles will program the eeprom at the selected address. if eempe is zero, setting eepe will have no effect. when eempe has been written to one by software, hardware clears the bit to zero after four clock cycles. ? bit 1 ? eepe: eeprom program enable the eeprom program enable signal eepe is the programming enable signal to the eeprom. when eepe is written, the eeprom will be programmed a ccording to the eepmn bits setting. the eempe bit must be written to one before a logical one is written to eepe, oth- erwise no eeprom write takes plac e. when the write access ti me has elapsed, the eepe bit is cleared by hardware. when eepe has been set, the cpu is halt ed for two cycles before the next instruction is executed. table 4-2. eeprom mode bits eepm1 eepm0 programming time operation 0 0 3.4 ms erase and write in one operation (atomic operation) 0 1 1.8 ms erase only 1 0 1.8 ms write only 1 1 ? reserved for future use
31 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 0 ? eere: eeprom read enable the eeprom read enable signal ? eere ? is the read strobe to the eeprom. when the correct address is set up in the eear register, the eere bit must be written to one to trigger the eeprom read. the eeprom read access take s one instruction, a nd the requested data is available immediately. when the eeprom is read, the cpu is halted for four cycles before the next instruction is executed. the user sh ould poll the eepe bit be fore starting the read operation. if a write operation is in progress, it is neither possible to read the eeprom, nor to change the eear register. 4.8.5.5 gpior2 ? general purpose i/o register 2 4.8.5.6 gpior1 ? general purpose i/o register 1 4.8.5.7 gpior0 ? general purpose i/o register 0 bit 76543210 0x15 (0x35) msb lsb gpior2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x14 (0x34) msb lsb gpior1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x13 (0x33) msb lsb gpior0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
32 9137e?rke?12/10 atmel ATA5771/73/74 4.9 system clock and clock options 4.9.1 clock systems and their distribution figure 4-10 on page 32 presents the principal clock systems in the atmel ? avr ? and their dis- tribution. all of the clocks need not be acti ve at a given time. in order to reduce power consumption, the clocks to modu les not being used can be halt ed by using different sleep modes, as described in section 4.10 ?power management and sleep modes? on page 41 . the clock systems are detailed below. figure 4-10. clock distribution 4.9.1.1 cpu clock ? clk cpu the cpu clock is routed to parts of the system concerned with operation of the avr core. examples of such modules are the general purpose register file, the status register and the data memory holding the stack po inter. halting the cpu clock i nhibits the core from perform- ing general operations and calculations. 4.9.1.2 i/o clock ? clk i/o the i/o clock is used by the majority of the i/o modules, like timer/counter. the i/o clock is also used by the external interrupt module, but note that some external interrupts are detected by asynchronous logic, allowing such interrupts to be detected even if the i/o clock is halted. 4.9.1.3 flash clock ? clk flash the flash clock controls operation of the flash interface. the flash clock is usually active simultaneously with the cpu clock. 4.9.1.4 adc clock ? clk adc the adc is provided with a dedicated clock domain. this allows halting the cpu and i/o clocks in order to reduce noise generated by digi tal circuitry. this gives more accurate adc conversion results. general i/o modules cpu core ram clk i/o a v r clock control unit clk cpu flash and eeprom clk flash source clock w atchdog timer w atchdog oscillator reset logic clock multiplexer w atchdog clock calibrated rc oscillator calibrated rc oscillator external clock adc clk adc crystal oscillator low-frequency crystal oscillator system clock prescaler
33 9137e?rke?12/10 atmel ATA5771/73/74 4.9.2 clock sources the device has the following clock source options , selectable by flash fuse bits as shown below. the clock from the selected source is input to the atmel ? avr ? clock generator, and routed to the appropriate modules. note: 1. for all fuses ?1? means unprogrammed while ?0? means programmed. the various choices for each clocking option is given in the following sections. when the cpu wakes up from power-down or power-save, the selected clock source is used to time the start-up, ensuring stable oscillator operation before instruction execution starts. when the cpu starts from reset, there is an additional delay allowing the power to reach a stable level before commencing normal op eration. the watchdog oscilla tor is used for timing this real-time part of the start-up time. the number of wdt oscillato r cycles used for each time-out is shown in table 4-4 . 4.9.3 default clock source the device is shipped with cksel = ?0010?, sut = ?10?, and ckdiv8 programmed. the default clock source setting is therefore the inte rnal rc oscillator runn ing at 8.0 mhz with lon- gest start-up time and an initial system clock pr escaling of 8, resulting in 1.0 mhz system clock. this default setting ensures that all users can make their desired clock source setting using an in-system or high-voltage programmer. 4.9.4 crystal oscillator xtal1 and xtal2 are input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in figure 4-11 on page 34 . either a quartz crystal or a ceramic resonator may be used. c1 and c2 should always be equal for both crystals and resonators. the optimal value of the capacitors depends on the crystal or resonator in use, the amount of stray capac-itance, and the electromagnetic noise of the environment. some initial guidelines for choosing capacitors for use with crystals are given in table 4-5 on page 34 . for ceramic resonators, the capacitor values given by the manufacturer should be used. table 4-3. device clocking options select (1) device clocking option cksel3..0 external clock 0000 calibrated internal rc oscillator 8.0 mhz 0010 watchdog oscillator 128 khz 0100 external low-frequency oscillator 0110 external crystal/ceramic resonator 1000-1111 reserved 0101, 0111, 0011,0001 table 4-4. number of watchdog oscillator cycles typ time-out number of cycles 4 ms 512 64 ms 8k (8,192)
34 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-11. crystal oscillator connections the oscillator can operate in three different modes, each optimized for a specific frequency range. the op erating mode is selected by t he fuses cksel3..1 as shown in table 4-5 . notes: 1. this option should not be used with crystals, only with ceramic resonators. the cksel0 fuse together with the sut1..0 fuses select the start-up times as shown in table 4-6 on page 35 . table 4-5. crystal oscillator operating modes cksel3..1 frequency range (mhz) recommended range for capacitors c1 and c2 for use with crystals (pf) 100 (1) 0.4 - 0.9 ? 101 0.9 - 3.0 12 - 22 110 3.0 - 8.0 12 - 22 111 8.0 - 12 - 22 xtal2 xtal1 gnd c2 c1
35 9137e?rke?12/10 atmel ATA5771/73/74 notes: 1. these options should only be used when not operating close to the maximum frequency of the device, and only if frequency stability at start-up is not important for the application. these options are not suitable for crystals. 2. these options are intended for use with ce ramic resonators and will ensure frequency stabil- ity at start-up. they can also be used with crystals when not operating close to the maximum frequency of the device, and if frequency stab ility at start-up is not important for the application. 4.9.5 low-frequency crystal oscillator to use a 32.768 khz watch crystal as the clock source for the device, the low-frequency crys- tal oscillator must be select ed by setting cksel fuses to ?0110?. the cryst al should be connected as shown in figure 4-11 on page 34 . see the 32 khz crysta l oscillator application note for details on osc illator operation and how to choose appropriate values for c1 and c2. when this oscillator is selected, start-up ti mes are determined by the sut fuses as shown in table 4-7 . notes: 1. these options should only be used if frequen cy stability at start-up is not important for the application. table 4-6. start-up times for the crysta l oscillator clock selection cksel0 sut1..0 start-up time from power-down and power-save additional delay from reset (v cc = 5.0v) recommended usage 000 258 ck (1) 14ck + 4.1 ms ceramic resonator, fast rising power 001 258 ck (1) 14ck + 65 ms ceramic resonator, slowly rising power 010 1k ck (2) 14ck ceramic resonator, bod enabled 011 1k ck (2) 14ck + 4.1 ms ceramic resonator, fast rising power 100 1k ck (2) 14ck + 65 ms ceramic resonator, slowly rising power 1 01 16k ck 14ck crystal oscillator, bod enabled 1 10 16k ck 14ck + 4.1 ms crystal oscillator, fast rising power 1 11 16k ck 14ck + 65 ms crystal oscillator, slowly rising power table 4-7. start-up times for the lo w frequency crystal oscillator clock selection sut1..0 start-up time from power down and power save additional delay from reset (v cc = 5.0v) recommended usage 00 1k ck (1) 4 ms fast rising power or bod enabled 01 1k ck (1) 64 ms slowly rising power 10 32k ck 64 ms stable frequency at start-up 11 reserved
36 9137e?rke?12/10 atmel ATA5771/73/74 4.9.6 calibrated internal rc oscillator by default, the internal rc oscillator provides an approximate 8 mhz clock. though voltage and temperature dependent, this clock can be very accurately calibrated by the the user. see table 8-1 on page 189 and section 8.3.8.9 ?internal oscillator speed? on page 207 for more details. the device is shipped with the ckdiv8 fuse programmed. see section 4.9.9 ?system clock prescaler? on page 38 for more details. this clock may be selected as the system cl ock by programming the cksel fuses as shown in table 4-8 . if selected, it will operate with no ex ternal components. du ring reset, hardware loads the pre-programmed calibration value into the osccal register and thereby automati- cally calibrates the rc oscillator. the accuracy of this calibration is shown as factory calibration in table 8-1 on page 189 . by changing the osccal register from sw, see section 4.9.10.1 ?osc illator calibration reg- ister ? osccal? on page 39 , it is possible to get a higher calibration accuracy than by using the factory calibration. the accuracy of this calibration is shown as user calibration in table 8-1 on page 189 . when this oscillator is used as the chip cloc k, the watchdog oscillato r will still be used for the watchdog timer and for the reset time-out. for more information on the pre-programmed calibration value, see the section section 4.23.4 ?calibration byte? on page 168 . note: 1. the device is shipped with this option selected. when this oscillator is selected, start-up times are determined by the sut fuses as shown in table 4-9 .. note: 1. the device is shipped with this option selected. table 4-8. internal calibrated rc o scillator operating modes cksel3..0 nominal frequency 0010 (1) 8.0 mhz table 4-9. start-up times for the internal calib rated rc oscillato r clock selection sut1..0 start-up time from power-down additional delay from reset (v cc = 5.0v) recommended usage 00 6 ck 14ck bod enabled 01 6 ck 14ck + 4 ms fast rising power 10 (1) 6 ck 14ck + 64 ms slowly rising power 11 reserved
37 9137e?rke?12/10 atmel ATA5771/73/74 4.9.7 external clock to drive the device from an external cloc k source, clki should be driven as shown in figure 4-12 . to run the device on an external clock, the cksel fuses must be programmed to ?0000?. figure 4-12. external clock drive configuration when this clock source is sele cted, start-up times are determined by the sut fuses as shown in table 4-10 . when applying an external clock, it is required to avoid sudden changes in the applied clock frequency to ensure stable operation of the mcu. a variation in frequency of more than 2% from one clock cycle to the next can lead to unpredictable behavior. it is required to ensure that the mcu is kept in reset during such changes in the clock frequency. note that the system clock prescaler can be used to implement run-time changes of the inter- nal clock frequency while still ensuring stable operation. see to section 4.9.9 ?system clock prescaler? on page 38 for details. table 4-10. start-up times for the external clock selection sut1..0 start-up time from power-down and power-save additional delay from reset recommended usage 00 6 ck 14ck bod enabled 01 6 ck 14ck + 4 ms fast rising power 10 6 ck 14ck + 64 ms slowly rising power 11 reserved external clock signal clki gnd
38 9137e?rke?12/10 atmel ATA5771/73/74 4.9.8 128 khz internal oscillator the 128khz internal osc illator is a low power oscillator pr oviding a clock of 128khz. the fre- quency is nominal at 3v and 25c. this clock may be select as the system clock by programming the cksel fuses to ?0100?. when this clock source is sele cted, start-up times are determined by the sut fuses as shown in table 4-11 . 4.9.9 system clock prescaler the atmel ? attiny44v system clock can be divided by setting the clock prescale register ? clkpr. this feature can be used to decrease power consumption when the requirement for processing power is low. this can be used with all clock source options, and it will affect the clock frequency of the cpu and all synchronous peripherals. clk i/o , clk adc , clk cpu , and clk flash are divided by a factor as shown in table 4-12 on page 40 . 4.9.9.1 switching time when switching between prescaler settings, the system clock presca ler ensures that no glitches occur in the clock system and that no intermediate frequency is higher than neither the clock frequency corresponding to the previous setting, nor the clock frequency corre- sponding to the new setting. the ripple counter that implements the prescaler runs at the frequency of the undivided clock, which may be faster than the cpu?s clock frequency. hence, it is not possible to determine the state of the prescaler ? even if it were readable, and the exact time it takes to switch from one clock division to another cannot be exactly predicted. from the time the clkps values are written, it takes between t1 + t2 and t1 + 2*t2 before the new clock frequency is active. in this interval, 2 active clock edges are produced. here, t1 is the previous clock period, and t2 is the pe riod corresponding to the new prescaler setting. table 4-11. start-up times for the 128 khz internal oscillator sut1..0 start-up time from power-down and power-save additional delay from reset recommended usage 00 6 ck 14ck bod enabled 01 6 ck 14ck + 4 ms fast rising power 10 6 ck 14ck + 64 ms slowly rising power 11 reserved
39 9137e?rke?12/10 atmel ATA5771/73/74 4.9.10 register description 4.9.10.1 oscillato r calibration register ? osccal the oscillator calibration register is used to trim the calibrated internal rc oscillator to remove process variations from the oscillator frequency. a pre-programmed calibration value is automatically written to this register during chip reset, giving the factory calibrated fre- quency as specified in table 8-1 on page 189 . the application software can write this register to change the o scillator frequency. the osc illator can be calibrated to frequencies as specified in table 8-1 on page 189 . calibration outside that range is not guaranteed. note that this oscillator is used to time eeprom and flash write accesses, and these write times will be affected accordingly. if the eepr om or flash are writt en, do not calibrate to more than 8.8 mhz. otherwise, the eeprom or flash write may fail. the cal7 bit determines the range of operation for the oscillato r. setting this bit to 0 gives the lowest frequency range, setting this bit to 1 gives the highest frequency range. the two fre- quency ranges are overlapping, in other words a setting of osccal = 0x7f gives a higher frequency than osccal = 0x80. the cal6..0 bits are used to tune the frequency within the selected range. a setting of 0x00 gives the lowest frequency in that range, and a setting of 0x7f gives the highest frequency in the range. 4.9.10.2 clock presca le register ? clkpr ? bit 7 ? clkpce: clock prescaler change enable the clkpce bit must be written to logic one to enable change of the clkps bits. the clk- pce bit is only updated when the other bits in clkpr are simultaniosly written to zero. clkpce is cleared by hard ware four cycles after it is written or w hen the clkps bits are writ- ten. rewriting the clkpce bit within this time-out period does neither extend the time-out period, nor clear the clkpce bit. ? bits 6..4 ? res: reserved bits these bits are reserved bits in the atmel ? attiny44v and will always read as zero. ? bits 3..0 ? clkps3..0: clock prescaler select bits 3 - 0 these bits define the division factor between the selected clock source and the internal sys- tem clock. these bits can be written run-time to vary the clock frequency to suit the application requirements. as the divider divides the master clock input to the mcu, the speed of all syn- chronous peripherals is reduced when a division factor is used. the division factors are given in table 4-12 on page 40 . bit 7 6 5 4 3 2 1 0 0x31 (0x51) cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 osccal read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value device specific calibration value bit 7 6 5 4 3 2 1 0 0x26 (0x46) clkpce ? ? ? clkps3 clkps2 clkps1 clkps0 clkpr read/write r/w r r r r/w r/w r/w r/w initial value 0 0 0 0 see bit description
40 9137e?rke?12/10 atmel ATA5771/73/74 to avoid unintentional changes of clock frequency, a special write procedure must be followed to change the clkps bits: 1. write the clock prescaler change enable (clkpce) bit to one and all other bits in clkpr to zero. 2. within four cycles, write the desired valu e to clkps while writing a zero to clkpce. interrupts must be disabled when changing prescaler setting to make sure the write procedure is not interrupted. the ckdiv8 fuse determines the initial value of the clkps bits . if ckdiv8 is unprogrammed, the clkps bits will be reset to ?0000?. if ckdiv8 is program med, clkps bits are reset to ?0011?, giving a division factor of eight at star t up. this feature should be used if the selected clock source has a higher frequency than the maximum frequency of the device at the present operating conditions. note that any value can be written to th e clkps bits rega rdless of the ckdiv8 fuse setting. the application software must ensure that a sufficient division factor is chosen if the selcted clock source has a higher frequency than the maximum frequency of the device at the present operating conditions. t he device is shipped with the ckdiv8 fuse programmed. table 4-12. clock prescaler select clkps3 clkps2 clkps1 clkps0 clock division factor 0000 1 0001 2 0010 4 0011 8 0100 16 0101 32 0110 64 0111 128 1000 256 1001 reserved 1010 reserved 1011 reserved 1100 reserved 1101 reserved 1110 reserved 1111 reserved
41 9137e?rke?12/10 atmel ATA5771/73/74 4.10 power management and sleep modes sleep modes enable the application to shut down unused modules in the mcu, thereby saving power. the atmel ? avr ? provides various sleep modes allowing the user to tailor the power consumption to the application?s requirements. 4.10.1 sleep modes figure 4-10 on page 32 presents the different clock systems in the atmel attiny44v, and their distribution. the figure is helpful in selecting an appropriate sleep mode. table 4-13 shows the different sleep modes and their wake up sources note: 1. for int0, only level interrupt. 2. only recommended with external crystal or resonator selected as clock source to enter any of the three sleep modes, the se bit in mcucr must be written to logic one and a sleep instruction must be exec uted. the sm1..0 bits in the mcucr register select which sleep mode (idle, adc noise reduction, standby or power-down) will be activated by the sleep instruct ion. see table 4-14 on page 44 for a summary. if an enabled interrupt occurs while the mcu is in a sleep mo de, the mcu wakes up. the mcu is then halted for four cycles in addition to the start-up time, executes the interrupt routine, and resumes execution from the instruction follow ing sleep. the contents of the register file and sram are unaltered when the device wakes up from sleep. if a reset occurs during sleep mode, the mcu wakes up and executes from the reset vector. 4.10.2 idle mode when the sm1..0 bits are written to 00, the sleep instruction makes the mcu enter idle mode, stopping the cpu but allowing analog comparator, adc, timer/counter, watchdog, and the interrupt system to continue operating. this sleep mode basically halts clk cpu and clk- flash , while allowing the other clocks to run. idle mode enables the mcu to wake up from external triggered interrupts as well as internal ones like the timer overflow. if wake-up from th e analog comparator interrupt is not required, the analog comparator can be powered down by setting the acd bit in the analog compara- tor control and status register ? acsr. this will reduce power consumption in idle mode. if the adc is enabled, a conversion starts au tomatically when this mode is entered. table 4-13. active clock domains and wake-up sources in the different sleep modes active clock domains osc illators wake-up sources sleep mode clk cpu clk flash clk io clk adc main clock source enabled int0 and pin change spm/ eeprom ready adc other i/o watchdog interrupt idle x x x x x x x x adc noise reduction xxx (1) xx x power-down x (1) x stand-by (2) xx (1)
42 9137e?rke?12/10 atmel ATA5771/73/74 4.10.3 adc noise reduction mode when the sm1..0 bits are written to 01, the sleep instruction makes the mcu enter adc noise reduction mode, stopping the cpu but allowing the adc, the external interrupts, and the watchdog to continue operating (if enabled). this sleep mode halts clk i/o , clk cpu , and clk- flash , while allowing the other clocks to run. this improves the noise environment for the adc, enabling higher resolution measurements. if the adc is enabled, a conversion starts automa tically when this mode is entered. apart form the adc conversion complete interrupt, only an external reset, a watchdog reset, a brown-out reset, an spm/eeprom ready interrupt, an external level interrupt on int0 or a pin change interrupt can wake up the mcu from adc noise reduction mode. 4.10.4 power-down mode when the sm1..0 bits are written to 10 , the sleep instruction makes the mcu enter power-down mode. in this mode, the oscillator is stopped, whil e the external interrupts, and the watchdog continue operating (if enabled). only an external reset, a watchdog reset, a brown-out reset, an external level interrupt on int0, or a pin change interrupt can wake up the mcu. this sleep mode halts all generated clocks, allowing opera tion of asynchronous modules only. note that if a level triggered interrupt is used for wake-up from power-down mode, the changed level must be held for some time to wake up the mcu. see section 4.13 ?external interrupts? on page 57 for details 4.10.5 standby mode when the sm1..0 bits are 11 and an external crystal/resonator clock option is selected, the sleep instruction makes the mcu enter standby mode. this mode is identical to power-down with the exception that the oscillator is kept running. from standby mode, the device wakes up in six clock cycles. 4.10.6 power reduction register the power reduction register (prr), see section 4.10.8.2 ?prr ? power reduction regis- ter? on page 44 , provides a method to stop the clock to individualperipherals to reduce power consumption. the current state of the peripheral is frozenand the i/o registers can not be read or written. resources used by the peripheral when stopping the clock will remain occupied, hence the peripheral should in most cases be disabled before stopping the clock. waking up a module, which is done by clearing the bit in prr, puts the module in the same state as before shutdown. module shutdown can be used in idle mode and active mode to significantly reduce the overall power consumption. see section 8.3.8.4 ?power-down supply current? on page 200 for exam- ples. in all other sleep modes, the clock is already stopped. 4.10.7 minimizing power consumption there are several issues to consider when tr ying to minimize the power consumption in an atmel ? avr ? controlled system. in general, sleep modes should be used as much as possi- ble, and the sleep mode should be selected so that as few as possible of the device?s functions are operating. all functions not needed sh ould be disabled. in particular, the follow- ing modules may need special consideration when trying to achieve the lowest possible power consumption.
43 9137e?rke?12/10 atmel ATA5771/73/74 4.10.7.1 analog to digital converter if enabled, the adc will be enabled in all sleep modes. to save power, the adc should be dis- abled before entering any sleep mode. when the adc is turned off and on again, the next conversion will be an ex tended conv ersion. see section 4.20 ?analog to digital converter? on page 140 for details on adc operation. 4.10.7.2 analog comparator when entering idle mode, the analog comparator should be disabled if not used. when enter- ing adc noise reduction mode, the analog com parator should be disabled. in the other sleep modes, the analog comparator is automat ically disabled. however, if the analog com- parator is set up to use the internal voltage reference as input, the analog comparator should be disabled in all sleep modes. otherwise, the internal voltage reference will be enabled, independent of sleep mode. see section 4.19 ?analog comparator? on page 137 for details on how to configure the analog comparator. 4.10.7.3 brown-out detector if the brown-out detector is not needed in the application, this module should be turned off. if the brown-out detector is enabled by the bo dlevel fuses, it will be enabled in all sleep modes, and hence, always cons ume power. in the de eper sleep modes, th is will contribute significantly to the total current consumption. see section 4.11.1.4 ?brown-out detection? on page 48 for details on how to configure the brown-out detector. 4.10.7.4 internal voltage reference the internal voltage re ference will be enabled wh en needed by the brow n-out detection, the analog comparator or the adc. if these modules are disabled as described in the sections above, the internal voltage reference will be disabled and it will not be consuming power. when turned on again, the user must allow the reference to start up before the output is used. if the reference is kept on in sleep mode, the output can be used immediately. see section 4.11.2 ?internal voltage reference? on page 49 for details on the start-up time. 4.10.7.5 watchdog timer if the watchdog timer is not needed in the application, this module should be turned off. if the watchdog timer is enabled, it w ill be enabled in all sleep mode s, and hence, always consume power. in the deeper sleep modes, this will contribute significantly to the total current con- sumption. see section 4.11.3 ?watchdog timer? on page 50 for details on how to configure the watchdog timer. 4.10.7.6 port pins when entering a sleep mode, all port pins should be configured to use minimum power. the most important thing is then to ensure that no pins drive resistive loads. in sleep modes where both the i/o clock (clk i/o ) and the adc clock (clk adc ) are stopped, the input buffers of the device will be disabled. this ensures that no power is consumed by the input logic when not needed. in some cases, the input logic is n eeded for detecting wake-up conditions, and it will then be enabled. see the section section 4.14.2.5 ?digital input enable and sleep modes? on page 65 for details on which pins are enabled. if the input buffer is enabled and the input sig- nal is left floating or has an analog signal level close to v cc /2, the input buffer will use excessive power.
44 9137e?rke?12/10 atmel ATA5771/73/74 for analog input pins, the digital input buffer should be disabled at all times. an analog signal level close to v cc /2 on an input pin can caus e significant current even in active mode. digital input buffers can be disabled by writing to the digital input disable register (didr0). see section 4.20.10.5 ?didr0 ? digital input disable register 0? on page 158 for details. 4.10.8 register description 4.10.8.1 mcucr ? mcu control register the mcu control register contains control bits for power management. ? bit 5 ? se: sleep enable the se bit must be written to logic one to make the mcu enter the sleep mode when the sleep instruction is executed. to avoid the mcu entering the slee p mode unless it is the pro- grammer?s purpose, it is recommended to write the sleep enable (se) bit to one just before the execution of the sleep inst ruction and to clear it im mediately after waking up. ? bits 4, 3 ? sm1..0: sleep mode select bits 2..0 these bits select between the three available sleep modes as shown in table 4-14 . note: 1. only recommended with external crystal or resonator selected as clock source ? bit 2 ? res: reserved bit this bit is a reserved bit in the atmel ? attiny44v and will always read as zero. 4.10.8.2 prr ? power reduction register ? bits 7, 6, 5, 4- res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 3- prtim1: power reduction timer/counter1 writing a logic one to this bit shuts down the timer/counter1 module. when the timer/counter1 is enabl ed, operation will continue like before the shutdown. bit 76543210 ? pud se sm1 sm0 ? isc01 isc00 mcucr read/write r r/w r/w r/w r/w r r/w r/w initial value 0 0 0 0 0 0 0 0 table 4-14. sleep mode select sm1 sm0 sleep mode 00idle 0 1 adc noise reduction 1 0 power-down 1 1 standby (1) bit 7 6 5 4 3 2 1 0 ? ? ? ? prtim1 prtim0 prusi pradc prr read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
45 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 2- prtim0: power reduction timer/counter0 writing a logic one to this bit shuts down the timer/counter0 module. when the timer/counter0 is enabl ed, operation will continue like before the shutdown. ? bit 1 - prusi: power reduction usi writing a logic one to this bit shuts down the usi by stopping the clock to the module. when waking up the usi again, the usi should be re initialized to ensure proper operation. ? bit 0 - pradc: power reduction adc writing a logic one to this bit shuts down t he adc. the adc must be disabled before shut down. the analog comparator cannot use the adc input mux when the adc is shut down. 4.11 system control and reset 4.11.1 resetting the atmel avr during reset, all i/o registers are set to their initial values, and the program starts execution from the reset vector. the instruction placed at the reset vector must be a rjmp ? relative jump ? instruction to the reset handling routine. if the program never enables an interrupt source, the interrupt vectors are not used, and regular program code can be placed at these locations. the circuit diagram in figure 4-13 on page 46 shows the reset logic. table 4-15 on page 47 defines the electrical parameters of the reset circuitry. the i/o ports of the atmel ? avr ? are immediately reset to their initial state when a reset source goes active. this does not requ ire any clock source to be running. after all reset sources have gone inactive, a delay counter is invoked, stretching the internal reset. this allows the power to reach a stable level before normal operation starts. the time-out period of the delay counter is defined by the us er through the sut and cksel fuses. the different selections for the delay period are presented in section 4.9.2 ?clock sources? on page 33 . 4.11.1.1 reset sources the attiny44v has four sources of reset: ? power-on reset. the mcu is reset when the supply voltage is below the power-on reset threshold (v pot ). ? external reset. the mcu is reset when a low level is present on the reset pin for longer than the minimum pulse length when reset function is enabled. ? watchdog reset. the mcu is reset when the watchdog timer period expires and the watchdog is enabled. ? brown-out reset. the mcu is re set when the supply voltage v cc is below the brown-out reset threshold (v bot ) and the brown-out detector is enabled.
46 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-13. reset logic 4.11.1.2 power-on reset a power-on reset (por) pulse is generated by an on-chip detection circuit. the detection level is defined in section 8.3.4 ?system and reset characterizations? on page 190 . the por is activated whenever v cc is below the detection level. the por circuit can be used to trigger the start-up reset, as well as to detect a failure in supply voltage. a power-on reset (por) circuit ensures that the device is reset from power-on. reaching the power-on reset threshold voltage invokes the delay counter, which determines how long the device is kept in reset after v cc rise. the reset signal is activated again, without any delay, when v cc decreases below t he detection level. figure 4-14. mcu start-up, reset tied to v cc mcu status register (mcusr) brown-out reset circuit bodlevel [1..0] delay counters cksel[1:0] ck timeout wdrf borf extrf porf data b u s clock generator spike filter pull-up resistor watchdog oscillator sut [ 1:0 ] power-on reset circuit reset time-out internal reset t tout v rst v porma x v cc ccrr v v pormin
47 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-15. mcu start-up, reset extended externally note: 1. before rising, the supply has to be between v pormin and v pormax to ensure a reset. 4.11.1.3 external reset an external reset is generated by a low level on the reset pin if enabled. reset pulses lon- ger than the minimum pulse width (see section 8.3.4 ?system and reset characterizations? on page 190 ) will generate a reset, even if the clock is not running. shorter pulses are not guaranteed to generate a reset. when the applied signal reaches the reset threshold voltage ? v rst ? on its positive edge, the delay counter starts the mcu after the time-out period ? t tout ? has expired. table 4-15. power on reset specifications symbol parameter min typ max units v pot power-on reset threshold voltage (rising) 1.1 1.4 1.7 v power-on reset threshold voltage (falling) (1) 0.8 1.3 1.6 v v pormax vcc max. start voltage to ensure internal power-on reset signal 0.4 v v pormin vcc min. start voltage to ensure internal power-on reset signal -0.1 v v ccrr vcc rise rate to ensure power-on reset 0.01 v/ms v rst reset pin threshold voltage 0.1 v cc 0.9v cc v reset time-out internal reset t tout v pot v rst v cc
48 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-16. external reset during operation 4.11.1.4 brown-out detection the atmel ? attiny44v has an on-chip brown-out dete ction (bod) circuit for monitoring the v cc level during operation by comparing it to a fixed trigger level. the trigger level for the bod can be selected by the bodlevel fuses. the trigger level has a hysteresis to ensure spike free brown-out detection. the hysteresis on the detection level should be interpreted as v bot+ =v bot + v hyst /2 and v bot- = v bot - v hyst /2. when the bod is enabled, and v cc decreases to a value be low the trigger level (v bot- in fig- ure 4-17 ), the brown-out reset is immediately activated. when v cc increases above the trigger level (v bot+ in figure 4-17 ), the delay counter starts the mcu after the time-out period t tout has expired. the bod circuit will only detect a drop in v cc if the voltage stays belo w the trigger level for lon- ger than t bod given in section 8.3.4 ?system and reset characterizations? on page 190 . figure 4-17. brown-out reset during operation cc v cc reset time-out internal reset v bot- v bot+ t tout
49 9137e?rke?12/10 atmel ATA5771/73/74 4.11.1.5 watchdog reset when the watchdog times out, it will generate a short reset pulse of one ck cycle duration. on the falling edge of this pulse, the delay timer starts counting the time-out period t tout . see section 4.11.3 ?watchdog timer? on page 50 for details on operation of the watchdog timer. figure 4-18. watchdog reset during operation 4.11.2 internal voltage reference the atmel ? attiny44v features an internal bandgap re ference. this reference is used for brown-out detection, and it can be used as an input to the analog comparator or the adc. 4.11.2.1 voltage reference enable signals and start-up time the voltage reference has a start-up time that may influence the way it should be used. the start-up time is given in section 8.3.4 ?system and reset characterizations? on page 190 . to save power, the reference is not always turned on. the reference is on during the following situations: 1. when the bod is enabled (by prog ramming the bodlevel [2..0] fuse). 2. when the bandgap reference is connected to the analog comparator (by setting the acbg bit in acsr). 3. when the adc is enabled. thus, when the bod is not enabled, after setting the acbg bit or enabling the adc, the user must always allow the reference to start up before the output from the analog comparator or adc is used. to reduce power consumption in power-down mode, the user can avoid the three conditions above to ensure that the refe rence is turned off before entering power-down mode. ck cc
50 9137e?rke?12/10 atmel ATA5771/73/74 4.11.3 watchdog timer the watchdog ti mer is clocked from an on-chip oscilla tor which runs at 128khz. by control- ling the watchdog timer prescaler, the watchdog reset interval can be adjusted as shown in table 4-18 on page 53 . the wdr ? watchdog reset ? instruction resets the watchdog timer. the watchdog timer is also reset when it is disabled and when a chip reset occurs. ten dif- ferent clock cycle periods can be selected to determine the reset period. if the reset period expires without another watchdog reset, the atti ny44v resets and executes from the reset vector. for timing details on the watchdog reset, refer to table 4-18 on page 53 . the wathdog timer can also be configured to generate an interrupt instead of a reset. this can be very helpful when using the watchdog to wake-up from power-down. to prevent unintentional disabling of the watchdog or unintentional change of time-out period, two different safety levels are selected by the fuse wdton as shown in table 4-16 see sec- tion 4.11.4 ?timed sequences for changing t he configuration of the watchdog timer? on page 50 for details. figure 4-19. watchdog timer 4.11.4 timed sequences for changing the configuration of the watchdog timer the sequence for changing configur ation differs slightly between the two safety levels. sepa- rate procedures are described for each level. 4.11.4.1 safety level 1 in this mode, the watchdog timer is initially disabled, but can be enabled by writing the wde bit to one without any restriction. a ti med sequence is needed when disabling an enabled watchdog timer. to disable an enabled watc hdog timer, the following procedure must be followed: table 4-16. wdt configuration as a function of the fuse settings of wdton wdton safety level wdt initial state how to disable the wdt how to change time-out unprogrammed 1 disabled timed sequence no limitations programmed 2 enabled always enabled timed sequence osc/2k osc/4k osc/8k osc/16k osc/32k osc/64k osc/128k osc/256k osc/512k osc/1024k mcu reset watchdog prescaler 128 khz oscillator watchdog reset wdp0 wdp1 wdp2 wdp3 wde
51 9137e?rke?12/10 atmel ATA5771/73/74 1. in the same operation, write a logic one to wdce and wde. a logic one must be writ- ten to wde regardless of the previous value of the wde bit. 2. within the next four clock cycles, in the same operation, write the wde and wdp bits as desired, but with the wdce bit cleared. 4.11.4.2 safety level 2 in this mode, the watchdog ti mer is always enabled, and the wde bit will always read as one. a timed sequence is needed when changing the watchdog time-out period. to change the watchdog time-out, the following procedure must be followed: 1. in the same operation, write a logical one to wdce and wde. even though the wde always is set, the wde must be written to one to start the timed sequence. 2. within the next four clock cycles, in the same operation, write the wdp bits as desired, but with the wdce bit cleared. the value written to the wde bit is irrelevant. 4.11.5 register description 4.11.5.1 mcusr ? mcu status register the mcu status register provides information on which reset source caused an mcu reset. ? bits 7..4 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 3 ? wdrf: watchdog reset flag this bit is set if a watchdog reset occurs. the bit is reset by a power- on reset, or by writing a logic zero to the flag. ? bit 2 ? borf: brown-out reset flag this bit is set if a brown-out reset occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 1 ? extrf: external reset flag this bit is set if an external reset occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 0 ? porf: power-on reset flag this bit is set if a power-on reset occurs. the bit is reset only by writing a logic zero to the flag. to make use of the reset flags to identify a reset condition, the user should read and then reset the mcusr as early as possible in the program. if the register is cleared before another reset occurs, the source of the reset can be found by examining the reset flags. bit 76543210 0x34 (0x54) ????wdrfborfextrfporfmcusr read/write rrrrr/wr/wr/wr/w initial value0000 see bit description
52 9137e?rke?12/10 atmel ATA5771/73/74 4.11.5.2 wdtcsr ? watchdog timer control and status register ? bit 7 ? wdif: watchdog timeout interrupt flag this bit is set when a time-out occurs in the watchdog timer and the watchdog timer is con- figured for interrupt. wdif is cleared by hard ware when executing the corresponding interrupt handling vector. alternatively, wdif is cleared by writing a logic one to the flag. when the i-bit in sreg and wdie are set, the watchd og time-out interrupt is executed. ? bit 6 ? wdie: watchdog timeout interrupt enable when this bit is written to one, wde is cleared, and the i-bit in the status register is set, the watchdog time-out interrupt is enabled. in this mode the corresponding interrupt is executed instead of a reset if a timeout in the watchdog timer occurs. if wde is set, wdie is automatically cleared by hardware when a time-out occurs. this is use- ful for keeping the watchdog reset security whil e using the interrupt. after the wdie bit is cleared, the next time-out will ge nerate a reset. to avoid the watchdog reset, wdie must be set after each interrupt. ? bit 4 ? wdce: watchdog change enable this bit must be set when the wd e bit is written to logic zero. otherwise, the watchdog will not be disabled. once written to one, hardware wi ll clear this bit after four clock cycles. see the description of the wde bit for a watchdog disable procedure. this bit must also be set when changing the pr escaler bits. see section 4.11.4 ?timed sequences for changing the configuration of the watchdog timer? on page 50 . ? bit 3 ? wde: watchdog enable when the wde is written to logic one, the watchdog timer is enabled, and if the wde is writ- ten to logic zero, the watchdog timer functi on is disabled. wde c an only be cleared if the wdce bit has logic level one. to disable an enabled watchdog timer, the following procedure must be followed: 1. in the same operation, write a logic one to wdce and wde. a logic one must be writ- ten to wde even though it is set to one before the disable operation starts. 2. within the next four clock cycles, write a logic 0 to wde. this disables the watchdog. in safety level 2, it is not possible to disable the watchdog timer, even with the algorithm described above. see section 4.11.4 ?timed sequences for changing the configuration of the watchdog timer? on page 50 . bit 76543210 0x21 (0x41) wdif wdie wdp3 wdce wde wdp2 wdp1 wdp0 wdtcsr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 x 0 0 0 table 4-17. watchdog timer configuration wde wdie watchdog timer state action on time-out 0 0 stopped none 0 1 running interrupt 1 0 running reset 1 1 running interrupt
53 9137e?rke?12/10 atmel ATA5771/73/74 in safety level 1, wde is overridden by wdrf in mcusr. see section 4.11.5.1 ?mcusr ? mcu status register? on page 51 for description of wdrf. this means that wde is always set when wdrf is set. to clear wde, wdrf must be cleared before disabling the watchdog with the procedure described above. this feature ensures multiple resets during conditions causing failure, and a safe start-up after the failure. note: if the watchdog timer is not going to be used in the application, it is important to go through a watchdog disable procedure in the initialization of the device. if the watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device will be reset, which in turn will lead to a new watchdog reset. to avoid this situation, the application software should always clear the wdrf flag and the wde control bit in the initialization routine. ? bits 5, 2..0 ? wdp3..0: watchdog timer prescaler 3, 2, 1, and 0 the wdp3..0 bits determine the watchdog timer prescaling when the watchdog timer is enabled. the different prescaling values and their corresponding timeout periods are shown in table 4-18 on page 53 . table 4-18. watchdog timer prescale select wdp3 wdp2 wdp1 wdp0 number of wdt oscillator cycles typical time-out at v cc = 5.0v 0 0 0 0 2k cycles 16 ms 0 0 0 1 4k cycles 32 ms 0 0 1 0 8k cycles 64 ms 0 0 1 1 16k cycles 0.125 s 0 1 0 0 32k cycles 0.25 s 0 1 0 1 64k cycles 0.5 s 0 1 1 0 128k cycles 1.0 s 0 1 1 1 256k cycles 2.0 s 1 0 0 0 512k cycles 4.0 s 1 0 0 1 1024k cycles 8.0 s 1010 reserved 1011 1100 1101 1110 1111
54 9137e?rke?12/10 atmel ATA5771/73/74 the following code example shows one assembly and one c function for turning off the wdt. the example assumes that interrupts are controlled (e.g., by disabling interrupts globally) so that no interrup ts will occur during execution of these functions. note: 1. see section 4.6 ?about code examples? on page 13 . assembly code example (1) wdt_off: wdr ; clear wdrf in mcusr ldi r16, (0< 55 9137e?rke?12/10 atmel ATA5771/73/74 4.12 interrupts this section describes the specifics of the interrupt handling as performed in atmel ? attiny44v. for a general explanation of the avr interrupt handling, see section 4.7.8 ?reset and interrupt handling? on page 19 . 4.12.1 interrupt vectors if the program never enables an interrupt source, the interrupt vectors are not used, and regu- lar program code can be placed at these locations. the most typical and general program setup for the reset and interrupt vector addresses in attiny44v is: table 4-19. reset and interrupt vectors vector no. program address source interrupt definition 1 0x0000 reset external pin, power-on reset, brown-out reset, watchdog reset 2 0x0001 int0 external interrupt request 0 3 0x0002 pcint0 pin change interrupt request 0 4 0x0003 pcint1 pin change interrupt request 1 5 0x0004 wdt watchdog time-out 6 0x0005 timer1 capt timer/counter1 capture event 7 0x0006 timer1 compa timer/counter1 compare match a 8 0x0007 timer1 compb timer/counter1 compare match b 9 0x0008 timer1 ovf timer/counter0 overflow 10 0x0009 timer0 compa timer/counter0 compare match a 11 0x000a timer0 compb timer/counter0 compare match b 12 0x000b timer0 ovf timer/counter0 overflow 13 0x000c ana_comp analog comparator 14 0x000d adc adc conversion complete 15 0x000e ee_rdy eeprom ready 16 0x000f usi_start usi start 17 0x0010 usi_ovf usi overflow
56 9137e?rke?12/10 atmel ATA5771/73/74 address labels code comments 0x0000 rjmp reset ; reset handler 0x0001 rjmp ext_int0 ; irq0 handler 0x0002 rjmp pcint0 ; pcint0 handler 0x0003 rjmp pcint1 ; pcint1 handler 0x0004 rjmp watchdog ; watchdog interrupt handler 0x0005 rjmp tim1_capt ; timer1 capture handler 0x0006 rjmp tim1_compa ; timer1 compare a handler 0x0007 rjmp tim1_compb ; timer1 compare b handler 0x0008 rjmp tim1_ovf ; timer1 overflow handler 0x0009 rjmp tim0_compa ; timer0 compare a handler 0x000a rjmp tim0_compb ; timer0 compare b handler 0x000b rjmp tim0_ovf ; timer0 overflow handler 0x000c rjmp ana_comp ; analog comparator handler 0x000d rjmp adc ; adc conversion handler 0x000e rjmp ee_rdy ; eeprom ready handler 0x000f rjmp usi_str ; usi start handler 0x0010 rjmp usi_ovf ; usi overflow handler ; 0x0011 reset: ldi r16, high(ramend); main program start 0x0012 out sph,r16 ; set stack pointer to top of ram 0x0013 ldi r16, low(ramend) 0x0014 out spl,r16 0x0015 sei ; enable interrupts 0x0016 xxx ... ... ... ...
57 9137e?rke?12/10 atmel ATA5771/73/74 4.13 external interrupts the external interrupts are triggered by the int0 pin or any of the pcint11..0 pins. observe that, if enabled, the interrupts will trigger even if the int0 or pcint11..0 pins are configured as outputs. this feature provides a way of generating a software interrupt. pin change 0 inter- rupts pci0 will trigger if any en abled pcint7..0 pin t oggles. pin change 1 interrupts pci1 will trigger if any enabled pcint11..8 pin toggles. the pcmsk0 and pcmsk1 registers control which pins contribute to the pin change interr upts. pin change interrupts on pcint11..0 are detected asynchronously. this implies that thes e interrupts can be used for waking the part also from sleep modes other than idle mode. the int0 interrupts can be triggered by a falling or rising edge or a low level. this is set up as indicated in the specification fo r the mcu control register ? m cucr. when the int0 interrupt is enabled and is configured as level triggered, t he interrupt will trigger as long as the pin is held low. note that recognition of falling or rising edge interrupts on int0 requires the pres- ence of an i/o clock, described in section 4.9.1 ?clock systems and their distribution? on page 32 . low level interrupt on int0 is detected asynchronously. this implies that this interrupt can be used for waking the part also from sleep modes other than idle mode. the i/o clock is halted in all sleep modes except idle mode. note that if a level tr iggered interrupt is used for wake-up from power-down, the required level must be held long enough for the mcu to complete the wake-up to trigger the level interrupt. if the level disappears before the end of the start-up time, the mcu will still wake up, but no interrupt will be generated. the start-up time is defined by the sut and cksel fuses as described in section 4.9 ?system clock and clock options? on page 32 . 4.13.1 pin change interrupt timing an example of timing of a pin change interrupt is shown in figure 4-20 . figure 4-20. timing of pin change interrupts clk pcint(0) pin_lat pin_sync pcint_in_(0) pcint_syn pcint_setflag pcif pcint(0) pin_sync pcint_syn pin_lat d q le pcint_setflag pcif clk clk pcint(0) in pcmsk(x) pcint_in_(0) 0 x
58 9137e?rke?12/10 atmel ATA5771/73/74 4.13.2 register description 4.13.2.1 mcucr ? mcu control register the external interrupt control register a contains control bits for interrupt sense control. ? bits 1, 0 ? isc01, isc00: interrupt sense control 0 bit 1 and bit 0 the external interrupt 0 is activated by the external pin int0 if the sreg i-flag and the corre- sponding interrupt mask are set. the level and edges on the external int0 pin that activate the interrupt are defined in table 4-20 . the value on the int0 pin is sampled before detecting edges. if edge or toggle interrupt is selected, pulses that last longe r than one clock period will generate an interrupt. shorter pulses are not guaranteed to generate an interrupt. if low level interrupt is selected, th e low level must be held until the co mpletion of the currently executing instruction to generate an interrupt. 4.13.2.2 gimsk ? general interrupt mask register ? bits 7, 3..0 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 6 ? int0: external interrupt request 0 enable when the int0 bit is set (one) and the i-bit in the status register (sreg) is set (one), the external pin interrupt is enabled. the interrupt sense control0 bits 1/0 (isc01 and isc00) in the external interrupt control register a (eicra) define whether the external interrupt is acti- vated on rising and/or falling edge of the int0 pin or level sensed. activity on the pin will cause an interrupt request even if int0 is configured as an output. the corresponding interrupt of external interrupt request 0 is execut ed from the int0 interrupt vector. ? bit 5 ? pcie1: pin change interrupt enable 1 when the pcie1 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 1 is enabled. any change on any enabled pcint11..8 pin will cause an inter- rupt. the corresponding interrupt of pin change interrupt request is executed from the pci1 interrupt vector. pcint11..8 pins are enabled individually by the pcmsk1 register. bit 76543210 0x35 (0x55) ? pud se sm1 sm0 ? isc01 isc00 mcucr read/write r r/w r/w r/w r/w r r/w r/w initial value 0 0 0 0 0 0 0 0 table 4-20. interrupt 0 sense control isc01 isc00 description 0 0 the low level of int0 generates an interrupt request. 0 1 any logical change on int0 generates an interrupt request. 1 0 the falling edge of int0 generates an interrupt request. 1 1 the rising edge of int0 generates an interrupt request. bit 76543210 0x3b (0x5b) ? int0 pcie1 pcie0 ? ? ? ? gimsk read/write rr/wr/wr/wrrrr initial value00000000
59 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 4? pcie0: pin change interrupt enable 0 when the pcie0 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 0 is enabled. any change on any enabled pcint7..0 pin will cause an inter- rupt. the corresponding interrupt of pin change interrupt request is executed from the pci0 interrupt vector. pcint7..0 pins are enabled individually by the pcmsk0 register. 4.13.2.3 gifr ? general interrupt flag register ? bits 7, 3..0 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 6 ? intf0: external interrupt flag 0 when an edge or logic change on the int0 pin triggers an interrupt request, intf0 becomes set (one). if the i-bit in sreg and the int0 bi t in gimsk are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alternatively, the flag can be cleared by writing a logical one to it. this flag is always cleared when int0 is configured as a level interrupt. ? bit 5 ? pcif1: pin change interrupt flag 1 when a logic change on any pcint11..8 pin tri ggers an interrupt request, pcif1 becomes set (one). if the i-bit in sreg a nd the pcie1 bit in gimsk are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cl eared when the interrupt routine is executed. alternatively, the flag can be cleared by writing a logical one to it. ? bit 4? pcif0: pin change interrupt flag 0 when a logic change on any pcint7..0 pin triggers an interrupt request, pcif becomes set (one). if the i-bit in sreg a nd the pcie0 bit in gimsk are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cl eared when the interrupt routine is executed. alternatively, the flag can be cleared by writing a logical one to it. 4.13.2.4 pcmsk1 ? pin change mask register 1 ? bits 7, 4? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bits 3..0 ? pcint11..8: pin change enable mask 11..8 each pcint11..8 bit selects whether pin change interrupt is enabled on the corresponding i/o pin. if pcint11..8 is set and the pcie1 bit in gimsk is set, pin change interrupt is enabled on the corresponding i/o pin. if pcint11..8 is cleared, pin change interrupt on the corresponding i/o pin is disabled. bit 76543210 0x3a (0x5a) ? intf0 pcif1 pcif0 ? ? ? ? gifr read/write rr/wr/wr/wrrrr initial value00000000 bit 7 6 5 4 3 2 1 0 0x20 (0x40) ? ? ? ? pcint11 pcint10 pcint9 pcint8 pcmsk1 read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
60 9137e?rke?12/10 atmel ATA5771/73/74 4.13.2.5 pcmsk0 ? pin change mask register 0 ? bits 7..0 ? pcint7..0: pin change enable mask 7..0 each pcint7..0 bit selects whether pin change interrupt is enabled on the corresponding i/o pin. if pcint7..0 is set and the pcie0 bit in gi msk is set, pin change interrupt is enabled on the corresponding i/o pin. if pcint7..0 is cl eared, pin change interrupt on the corresponding i/o pin is disabled. 4.14 i/o ports 4.14.1 overview all avr ? ports have true read-modify-write functionality when used as general digital i/o ports. this means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the sbi and cbi instructions. the same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). each output buffer has symmetrical drive characteristics with both high sink and source capability. the pin driver is strong enough to drive led displays directly. all port pins have individually selectable pull-up resistors with a supply-voltage invariant resis- tance. all i/o pins have pr otection diodes to both v cc and ground as indicated in figure 4-21 . see section 8. ?electrical characteristics? on page 186 for a complete list of parameters. figure 4-21. i/o pin equivalent schematic all registers and bit references in this section are written in general form. a lower case ?x? rep- resents the numbering letter for the port, and a lower case ?n? represents the bit number. however, when using the register or bit defines in a program, the precise form must be used. for example, portb3 for bit no. 3 in port b, here documented generally as portxn. the physical i/o registers and bit locations are listed in table 4-29 . bit 76543210 0x12 (0x32) pcint7 pcint6 pcint5 pcint4 pcint3 pcint2 pcint1 pcint0 pcmsk0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 c pin logic r pu see figure "general digital i/o" for details pxn
61 9137e?rke?12/10 atmel ATA5771/73/74 three i/o memory address locations are allocated for each port, one each for the data regis- ter ? portx, data direction register ? ddrx, and the port input pins ? pinx. the port input pins i/o location is read only, while the data register and the data direction register are read/write. however, writing a logic one to a bit in the pinx register, will result in a toggle in the corresponding bit in the data register. in addition, the pull-up disable ? pud bit in mcucr disables the pull-up function for all pins in all ports when set. using the i/o port as general digital i/o is described in section 4.14.2 ?ports as general digi- tal i/o? on page 61 . most port pins are multiplexed with alternate functions for the peripheral features on the device. how each alternate functi on interferes with the port pin is described in section 4.14.3 ?alternate port functions? on page 66 . refer to the indivi dual module sections for a full description of the alternate functions. note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital i/o. 4.14.2 ports as general digital i/o the ports are bi-directional i/o ports with optional internal pull-ups. figure 4-22 shows a func- tional description of one i/o-port pin, here generically called pxn. figure 4-22. general digital i/o (1) note: 1. wrx, wpx, wdx, rrx, rpx, and rdx are co mmon to all pins within the same port. clk i/o , sleep, and pud are common to all ports. clk rpx rrx rdx wdx pud synchronizer wdx: write ddrx wrx: write portx rrx: read portx register rpx: read portx pin pud: pullup disable clk i/o : i/o clock rdx: read ddrx d l q q reset reset q q d q q d clr portxn q q d clr ddxn pinxn data bus sleep sleep: sleep control pxn i/o wpx 0 1 wrx wpx: write pinx register
62 9137e?rke?12/10 atmel ATA5771/73/74 4.14.2.1 configuring the pin each port pin consists of three register bits: ddxn, portxn, and pinxn. as shown in table 4-29 on page 74 , the ddxn bits are accessed at the ddrx i/o address, the portxn bits at the portx i/o address, and the pinxn bits at the pinx i/o address. the ddxn bit in the ddrx register selects the direction of this pin. if ddxn is written logic one, pxn is configured as an output pin. if ddxn is wr itten logic zero, pxn is configured as an input pin. if portxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated. to switch the pull-up resistor off, portxn has to be written logic zero or the pin has to be configured as an output pin. the port pins are tri-stated when reset condition becomes active, even if no clocks are running. if portxn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). if portxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). 4.14.2.2 toggling the pin writing a logic one to pinxn toggles the value of portxn, independent on the value of ddrxn. note that the sbi instruction can be used to toggle one single bit in a port. 4.14.2.3 switching between input and output when switching between tri-state ({ddxn, portxn} = 0b00) and output high ({ddxn, portxn} = 0b11), an intermediate state with either pull-up enabled {ddxn, portxn} = 0b01) or output low ({ddxn, portxn} = 0b10) must occur. normally, the pull-up enabled state is fully acceptable, as a high-impedant environment will not notice the difference between a strong high driver and a pull-up. if this is not the case, the pud bit in the mcucr register can be set to disable all pull-ups in all ports. switching between input with pull-up and output low generates the same problem. the user must use either the tri-state ({ddxn, portxn} = 0b00) or the output high state ({ddxn, portxn} = 0b10) as an intermediate step. table 4-21 summarizes the control signals for the pin value. table 4-21. port pin configurations ddxn portxn pud (in mcucr) i/o pull-up comment 0 0 x input no tri-state (hi-z) 0 1 0 input yes pxn will source current if ext. pulled low. 0 1 1 input no tri-state (hi-z) 1 0 x output no output low (sink) 1 1 x output no output high (source)
63 9137e?rke?12/10 atmel ATA5771/73/74 4.14.2.4 reading the pin value independent of the setting of data direction bit ddxn, the port pin can be read through the pinxn register bit. as shown in figure 4-22 on page 61 , the pinxn register bit and the pre- ceding latch constitute a synchr onizer. this is needed to avoid metastability if the physical pin changes value near the edge of the internal clock, but it also introduces a delay. figure 4-23 shows a timing diagram of the synchronization when reading an externally applied pin value. the maximum and minimum propagation delays are denoted t pd,max and t pd,min respectively. figure 4-23. synchronization when reading an externally applied pin value consider the clock period starting shortly after the first falling edge of the system clock. the latch is closed when the clock is low, and goes transparent when the cl ock is high, as indi- cated by the shaded region of the ?sync latch? signal. the signal value is latched when the system clock goes low. it is clocked into the pi nxn register at the succeeding positive clock edge. as indicated by the two arrows tpd,max and tpd,min, a single signal transition on the pin will be delayed between ? and 1? system clock period depending upon the time of assertion. when reading back a software assigned pin value, a nop instruction must be inserted as indi- cated in figure 4-24 on page 64 . the out instruction sets the ?sync latch? signal at the positive edge of the clock. in this case, the delay tpd through the synchronizer is one system clock period. xxx in r17, pinx 0x00 0xff instructions sync latch pinxn r17 xxx system clk t pd, max t pd, min
64 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-24. synchronization when reading a software assigned pin value the following code example shows how to set port a pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 5 as input with a pull-up assigned to port pin 4. the resulting pin values are read back again, but as previously discussed, a nop instruction is included to be able to read back the value recently assigned to some of the pins. assembly code example (1) ... ; define pull-ups and set outputs high ; define directions for port pins ldi r16,(1< 65 9137e?rke?12/10 atmel ATA5771/73/74 note: 1. for the assembly program, two temporary registers are used to minimize the time from pull-ups are set on pins 0, 1 and 4, until the dire ction bits are correctly set, defining bit 2 and 3 as low and redefining bits 0 and 1 as strong high drivers. 4.14.2.5 digital input enable and sleep modes as shown in figure 4-22 on page 61 , the digital input signal can be clamped to ground at the input of the schmitt-trigger. the signal denoted sleep in the figure, is set by the mcu sleep controller in power-down mode, power-save mode, and standby mode to avoid high power consumption if some input signals are left floa ting, or have an analog signal level close to v cc /2. sleep is overridden for port pins enabled as ex ternal interrupt pins. if the external interrupt request is not enabled, sleep is active also fo r these pins. sleep is al so overridden by vari- ous other alternate func tions as described in section 4.14.3 ?alternate port functions? on page 66 . if a logic high level (?one?) is present on an asynchronous external interrupt pin configured as ?interrupt on rising edge, falling edge, or any logic change on pin? while the external inter- rupt is not enabled, the correspo nding external inte rrupt flag will be set when resuming from the above mentioned sleep mode, as the clamping in these sleep mode produces the requested logic change. 4.14.2.6 unconnected pins if some pins are unused, it is recommended to ensure that these pins have a defined level. even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to reduc e current consumption in all other modes where the digital inputs are enabled (reset, active mode and idle mode). the simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. in this case, the pull- up will be disabled during reset. if low power consumption during reset is important, it is recommended to use an external pull-up or pulldown. connecting unused pins directly to v cc or gnd is not recommended, sinc e this may cause excessive cur- rents if the pin is accidentally configured as an output.
66 9137e?rke?12/10 atmel ATA5771/73/74 4.14.3 alternate port functions most port pins have alternate functions in addition to being general digital i/os. figure 4-25 shows how the port pin control signals from the simplified figure 4-22 on page 61 can be over- ridden by alternate functions. the overriding signal s may not be present in all port pins, but the figure serves as a generic description applicable to all port pins in the avr ? microcontroller family. figure 4-25. alternate port functions (1) note: 1. wrx, wpx, wdx, rrx, rpx, and rdx are co mmon to all pins within the same port. clk i/o , sleep, and pud are common to all ports. all other signals are unique for each pin. table 4-22 on page 67 summarizes the function of the overriding signals. the pin and port indexes from figure 4-25 are not shown in the succeeding tables. the overriding signals are generated internally in the modules having the alternate function. clk rpx rrx wrx rdx wdx pud synchronizer wdx: write ddrx wrx: write portx rrx: read portx register rpx: read portx pin pud: pullup disable clk i/o : i/o clock rdx: read ddrx d l q q set clr 0 1 0 1 0 1 dixn aioxn dieoexn pvovxn pvoexn ddovxn ddoexn puoexn puovxn puoexn: pxn pull-up override enable puovxn: pxn pull-up override value ddoexn: pxn data direction override enable ddovxn: pxn data direction override value pvoexn: pxn port value override enable pvovxn: pxn port value override value dixn: digital input pin n on portx aioxn: analog input/output pin n on portx reset reset q q d clr q q d clr q q d clr pinxn portxn ddxn data bus 0 1 dieovxn sleep dieoexn: pxn digital input-enable override enable dieovxn: pxn digital input-enable override value sleep: sleep control pxn i/o 0 1 ptoexn ptoexn: pxn, port toggle override enable wpx: write pinx wpx
67 9137e?rke?12/10 atmel ATA5771/73/74 the following subsections shortly describe the alternate functions for each port, and relate the overriding signals to the alternate function. refer to the alternate function description for fur- ther details. table 4-22. generic description of overriding signals for alternate functions signal name full name description puoe pull-up override enable if this signal is set, the pull-up enable is controlled by the puov signal. if this signal is cleared, the pull-up is enabled when {ddxn, portxn, pud} = 0b010. puov pull-up override value if puoe is set, the pull-up is enabled/disabled when puov is set/cleared, regardle ss of the setting of the ddxn, portxn, and pud register bits. ddoe data direction override enable if this signal is set, the output driver enable is controlled by the ddov signal. if this signal is cleared, the output driver is enabled by the ddxn register bit. ddov data direction override value if ddoe is set, the output driver is enabled/disabled when ddov is set/cleared, regardless of the setting of the ddxn register bit. pvoe port value override enable if this signal is set and the output driver is enabled, the port value is controlled by the pvov signal. if pvoe is cleared, and the output driver is enabled, the port value is controlled by the portxn register bit. pvov port value override value if pvoe is set, the port value is set to pvov, regardless of the setting of the portxn register bit. ptoe port toggle override enable if ptoe is set, the portxn register bit is inverted. dieoe digital input enable override enable if this bit is set, the digital in put enable is controlled by the dieov signal. if this signal is cleared, the digital input enable is determined by mcu state (normal mode, sleep mode). dieov digital input enable override value if dieoe is set, the digital in put is enabled/disabled when dieov is set/cleared, regardl ess of the mcu state (normal mode, sleep mode). di digital input this is the digital input to alternate functions. in the figure, the signal is connected to the output of the schmitt-trigger but before the synchronizer. unless the digital input is used as a clock source, the module with the alternate function will use its own synchronizer. aio analog input/output this is the analog input/output to/from alternate functions. the signal is connected directly to the pad, and can be used bi-directionally.
68 9137e?rke?12/10 atmel ATA5771/73/74 4.14.3.1 alternate functions of port a the port a pins with alternate function are shown in table 4-27 on page 72 . ? port a, bit 0 ? adc0/aref/pcint0 adc0: analog to digital converter, channel 0 . aref: external analog reference for adc. pullup and output driver are disabled on pa0 when the pin is used as an external refer ence or internal voltage reference with external capacitor at the aref pin by setting (one) the bit refs0 in the adc multiplexer selection register (admux). pcint0: pin change interrupt source 0. the pa0 pin can serve as an external interrupt source for pin change interrupt 0. table 4-23. port a pins alternate functions port pin alternate function pa 0 adc0: adc input channel 0. aref: external analog reference. pcint0: pin change interrupt 0 source 0. pa 1 adc1: adc input channel 1. ain0: analog comparator positive input. pcint1:pin change interrupt 0 source 1. pa 2 adc2: adc input channel 2. ain1: analog comparator negative input. pcint2: pin change interrupt 0 source 2. pa 3 adc3: adc input channel 3. t0: timer/counter0 counter source. pcint3: pin change interrupt 0 source 3. pa 4 adc4: adc input channel 4. usck: usi clock three wire mode. scl : usi clock two wire mode. t1: timer/counter1 counter source. pcint4: pin change interrupt 0 source 4. pa 5 adc5: adc input channel 5. do: usi data output three wire mode. oc1b: timer/counter1 compare match b output. pcint5: pin change interrupt 0 source 5. pa 6 adc6: adc input channel 6. di: usi data input three wire mode. sda: usi data input two wire mode. oc1a: timer/counter1 compare match a output. pcint6: pin change interrupt 0 source 6. pa 7 adc7: adc input channel 7. oc0b: timer/counter0 compare match b output. icp1: timer/counter1 input capture pin. pcint7: pin change interrupt 0 source 7.
69 9137e?rke?12/10 atmel ATA5771/73/74 ? port a, bit 1 ? adc1/ain0/pcint1 adc1: analog to digital converter, channel 1 . ain0: analog comparator positive input. configure the port pin as input with the internal pull-up switched off to avoid the digital port function from interfering with the function of the analog comparator. pcint1: pin change interrupt source 1. the pa1 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 2 ? adc2/ain1/pcint2 adc2: analog to digital converter, channel 2 . ain1: analog comparator negative input. configure the port pin as input with the internal pull-up switched off to avoid the digital port function from interfering with the function of the analog comparator. pcint2: pin change interrupt source 2. the pa2 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 3 ? adc3/t0/pcint3 adc3: analog to digital converter, channel 3 . t0: timer/counter0 counter source. pcint3: pin change interrupt source 3. the pa3 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 4 ? adc4/usck/scl/t1/pcint4 adc4: analog to digital converter, channel 4 . usck: three-wire mode univer sal serial interface clock. scl: two-wire mode serial clock for usi two-wire mode. t1: timer/counter1 counter source. pcint4: pin change interrupt source 4. the pa4 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 5 ? adc5/do/oc1b/pcint5 adc5: analog to digital converter, channel 5 . do: data output in usi three-wire mode. data output (do) overrides porta5 value and it is driven to the port when the data direction bit dda5 is set (one). howe ver the porta5 bit still controls the pullup, enabling pullup if dire ction is input and po rta5 is set(one). oc1b: output compare match output: the pa5 pin can serve as an external output for the timer/counter1 compare match b. the pa5 pin has to be configured as an output (dda5 set (one)) to serve this function. the oc1b pin is also the output pin for the pwm mode timer function. pcint5: pin change interrupt source 5. the pa5 pin can serve as an external interrupt source for pin change interrupt 0.
70 9137e?rke?12/10 atmel ATA5771/73/74 ? port a, bit 6 ? adc6/di/sda/oc1a/pcint6 adc6: analog to digital converter, channel 6 . sda: two-wire mode serial interface data. di: data input in usi three-wire mode. usi three-wire mode does not override normal port functions, so pin must be configure as an input for di function. oc1a, output compare match output: the pa6 pin can serve as an external output for the timer/counter1 compare match a. the pa6 pin has to be configured as an output (dda6 set (one)) to serve this function. the oc1a pin is also the output pin for the pwm mode timer function. pcint6: pin change interrupt source 6. the pa6 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 7 ? adc7/oc0b/icp1/pcint7 adc7: analog to digital converter, channel 7 . oc1b, output compare match output: the pa7 pin can serve as an external output for the timer/counter1 compare match b. the pa7 pin has to be configured as an output (dda7 set (one)) to serve this function. the oc1b pin is also the output pin for the pwm mode timer function. icp1, input capture pin: the pa7 pin can act as an input capture pin for timer/counter1. pcint7: pin change interrupt source 7. the pa7 pin can serve as an external interrupt source for pin change interrupt 0. table 4-24 to table 4-26 on page 71 relate the alternate functions of port a to the overriding signals shown in table 4-25 on page 71 . table 4-24. overriding signals for alternate functions in pa7..pa5 signal name pa7/adc7/oc0b/icp1/ pcint7 pa6/adc6/di/sda/oc1a/ pcint6 pa5/adc5/do/oc1b/ pcint5 puoe000 puov000 ddoe 0 usiwm1 0 ddov 0 (sda + porta6 ) ? ddra6 0 pvoe oc0b enable (usiwm1 ? dda6) + oc1a enable (usiwm1 ? usiwm0) + oc1b enable pvov oc0b ( usiwm1 ? dda6) ? oc1a usiwm1 ? usiwm0 ? do + (~usiwm1 ? usiwm0) ? oc1b} ptoe000 dieoe pcint7 ? pcie0 + adc7d usisie + (pcint6 ? pcie0) + adc6d pcint5 ? pcie + adc5d dieov pcint7 ? pcie0 usisie + pcint7 ? pcie0 pcint5 ? pcie di pcint7/icp1 input di/sda/pcint6 input pcint5 input aio adc7 input adc6 input adc5 input
71 9137e?rke?12/10 atmel ATA5771/73/74 table 4-25. overriding signals for alternate functions in pa4..pa2 signal name pa4/adc4/usck/scl/t1/ pcint4 pa3/adc3/t0/pcint3 pa2/adc2/ain1/pcint2 puoe000 puov000 ddoe usiwm1 0 0 ddov usi_scl_hold + porta4 ) ? adc4d 00 pvoe usiwm1 ? adc4d 0 0 pvov000 ptoe usi_ptoe 0 0 dieoe usisie + (pcint4 ? pcie0) + adc4d (pcint3 ? pcie0) + adc3d pcint2 ? pcie + adc2d dieov usisie + (pcint4 ? pcie0) pcint3 ? pcie0 pcint3 ? pcie0 di usck/scl/t1/pcint4 input pcint1 input pcint0 input aio adc4 input adc3 input adc2/analog comparator negative input table 4-26. overriding signals for alternate functions in pa1..pa0 signal name pa1/adc1/ain0/pcint1 pa0/adc0/aref/pcint0 puoe 0 reset ? (refs1 ? refs0 + refs1 ? refs0) puov 0 0 ddoe 0 reset ? (refs1 ? refs0 + refs1 ? refs0) ddov 0 0 pvoe 0 reset ? (refs1 ? refs0 + refs1 ? refs0) pvov 0 0 ptoe 0 0 dieoe pcint1 ? pcie0 + adc1d pcint0 ? pcie0 + adc0d dieov pcint1 ? pcie0 pcint0 ? pcie0 di pcint1 input pcint0 input aio adc1/analog comparator positive input adc1 input analog reference
72 9137e?rke?12/10 atmel ATA5771/73/74 4.14.3.2 alternate functions of port b the port b pins with alternate function are shown in table 4-27 . ? port b, bit 0 ? xtal1/pcint8 xtal1: chip clock oscilla tor pin 1. used for all chip clock sources except internal calibrateble rc oscillator. when used as a clock pin, the pin can not be used as an i/o pin. when using internal calibratable rc oscillato r as a chip clock source, pb0 serves as an ordinary i/o pin. pcint8: pin change interrupt source 8. the pb0 pin can serve as an external interrupt source for pin change interrupt 1. ? port b, bit 1 ? xtal2/pcint9 xtal2: chip clock oscillator pin 2. used as clock pin for all chip clock sources except internal calibrateble rc oscillator and external clock. when used as a clock pin, the pin can not be used as an i/o pin. when using internal calibra table rc oscillator or external clock as a chip clock sources, pb1 serves as an ordinary i/o pin. pcint9: pin change interrupt source 9. the pb1 pin can serve as an external interrupt source for pin change interrupt 1. ? port b, bit 2 ? int0/oc0a/ckout/pcint10 int0: external interrupt request 0. oc0a: output compare match output: the pb2 pin can serve as an external output for the timer/counter0 compare match a. the pb2 pin has to be configured as an output (ddb2 set (one)) to serve this function. the oc0a pin is also the output pin for the pwm mode timer function. ckout - system clock output: the system cl ock can be output on the pb2 pin. the system clock will be output if the ckout fuse is pr ogrammed, regardless of the portb2 and ddb2 settings. it will also be output during reset. pcint10: pin change interrupt source 10. t he pb2 pin can serve as an external interrupt source for pin change interrupt 1. table 4-27. port b pins alternate functions port pin alternate function pb0 xtal1: crystal oscillator input. pcint8: pin change interrupt 1 source 8. pb1 xtal2: crystal oscillator output. pcint9: pin change interrupt 1 source 9. pb2 int0: external interrupt 0 input. oc0a: timer/counter0 compare match a output. ckout: system clock output. pcint10:pin change interrupt 1 source 10. pb3 reset: reset pin. dw: debugwire i/o. pcint11:pin change interrupt 1 source 11.
73 9137e?rke?12/10 atmel ATA5771/73/74 ? port b, bit 3 ? reset /dw/pcint11 reset : external reset input is active low and enabled by unprogramming (?1?) the rst- disbl fuse. pullup is activated and output driver and digital input are deactivated when the pin is used as the reset pin. dw: when the debugwire enable (dwen) fuse is programmed and lock bits are unpro- grammed, the debugwire system within the target device is activated. the reset port pin is configured as a wire-and (open-drain) bi-directional i/o pin with pull-up enabled and becomes the communication gateway between target and emulator. pcint11: pin change interrupt source 11. t he pb3 pin can serve as an external interrupt source for pin change interrupt 1. table 4-28 and table 4-29 on page 74 relate the alternate functions of port b to the overriding signals shown in figure 4-25 on page 66 . table 4-28. overriding signals for alternate functions in pb3..pb2 signal name pb3/ reset /dw/ pcint11 pb2/int0/oc0a/ckout/pcint10 puoe rstdisbl (1) + debugwire_enable (2) 1. rstdisbl is 1 when the fuse is ?0? (programmed). 2. debugwire is enabled wheb dwen fuse is programmed and lock bits are unprogrammed. ckout puov 1 0 ddoe rstdisbl (1) + debugwire_enable (2) ckout ddov debugwire_enable (2) ? debugwire tr a n s m i t 1'b1 pvoe rstdisbl (1) + debugwire_enable (2 ckout + oc0a enable pvov 0 ckout ? system clock + ckout ? oc0a ptoe 0 0 dieoe rstdisbl (1) + debugwire_enable (2) + pcint11 ? pcie1 pcint10 ? pcie1 + int0 dieov debugwire_enable (2) + (rstdisbl (1) ? pcint11 ? pcie1) pcint10 ? pcie1 + int0 di dw/pcint11 input int0/pcint10 input aio
74 9137e?rke?12/10 atmel ATA5771/73/74 4.14.4 register description 4.14.4.1 mcucr ? mcu control register ? bits 7, 2? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 6 ? pud: pull-up disable when this bit is written to one, the pull-ups in the i/o ports are disabled even if the ddxn and portxn registers are configured to enable the pull-ups ({ddxn, portxn} = 0b01). see sec- tion 4.14.2.1 ?configuring the pin? on page 62 for more details about this feature. 4.14.4.2 porta ? port a data register table 4-29. overriding signals for alternate functions in pb1..pb0 signal name pb1/xtal2/pcin t9 pb0/xtal1/pcint8 puoe ext_osc (1) 1. ext_osc = crystal oscillator or low frequency crystal oscillator is selected as system clock. ext_clock (2) + ext_osc (1) 2. ext_clock = external clock is selected as system clock. puov 0 0 ddoe ext_osc (1) ext_clock (2) + ext_osc (1) ddov 0 0 pvoe ext_osc (1) ext_clock (2) + ext_osc (1) pvov 0 0 ptoe 0 0 dieoe ext_osc (1) + pcint9 ? pcie1 ext_clock (2 + ext_osc (1) + (pcint8 ? pcie1) dieov ext_osc (1) ? pcint9 ? pcie1 ( ext_clock (2) ? pwr_down ) + (ext_clock (2) ? ext_osc (1) ? pcint8 ? pcie1) di pcint9 input clock/pcint8 input aio xtal2 xtal1 bit 7 6 5 4 3 2 1 0 ?pud se sm1 sm0 ? isc01 isc00 mcucr read/write r r/w r/w r/w r/w r r r initial value 0 0 0 0 0 0 0 0 bit 76543210 0x1b (0x3b) porta7 porta6 porta5 porta4 porta3 porta2 porta1 porta0 porta read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
75 9137e?rke?12/10 atmel ATA5771/73/74 4.14.4.3 ddra ? port a data direction register 4.14.4.4 pina ? port a input pins address 4.14.4.5 portb ? port b data register 4.14.4.6 ddrb ? port b data direction register 4.14.4.7 pinb ? port binput pins address bit 76543210 0x1a (0x3a) dda7 dda6 dda5 dda4 dda3 dda2 dda1 dda0 ddrb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 0x19 (0x39) pina7 pina6 pina5 pina4 pi na3 pina2 pina1 pina0 pinb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 n/a n/a n/a n/a n/a n/a bit 76543210 0x18 (0x38) ? ? portb3 portb2 portb1 portb0 portb read/writerrrrr/wr/wr/wr/w initial value00000000 bit 76543210 0x17 (0x37) ?? ddb3 ddb2 ddb1 ddb0 ddrb read/write r r r r r/w r/w r/w r/w initial value00000000 bit 76543210 0x16 (0x36) ?? pinb3 pinb2 pinb1 pinb0 pinb read/write r r r r r/w r/w r/w r/w initial value 0 0 n/a n/a n/a n/a n/a n/a
76 9137e?rke?12/10 atmel ATA5771/73/74 4.15 8-bit timer/counter0 with pwm 4.15.1 features ? two independent output compare units ? double buffered outp ut compare registers ? clear timer on compare match (auto reload) ? glitch free, phase correct pulse width modulator (pwm) ? variable pwm period ? frequency generator ? three independent interrupt sources (tov0, ocf0a, and ocf0b) 4.15.2 overview timer/counter0 is a general purpose 8-bit ti mer/counter module, with two independent out- put compare units, and with pwm support. it allows accurate program execution timing (event management) and wave generation. a simplified block diagram of the 8-bit timer/counter is shown in figure 4-26 . for the actual placement of i/o pins. cpu accessible i/o r egisters, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit locations are listed in the section 4.9.10 ?register description? on page 39 . figure 4-26. 8-bit timer/counter block diagram clock select timer/counter data bus ocrna ocrnb = = tcntn waveform generation waveform generation ocna ocnb = fixed top value control logic = 0 top bottom count clear direction tovn (int.req.) ocna (int.req.) ocnb (int.req.) tccrna tccrnb tn edge detector ( from prescaler ) clk tn
77 9137e?rke?12/10 atmel ATA5771/73/74 4.15.2.1 registers the timer/counter (tcnt0) and output compare registers (ocr0a and ocr0b) are 8-bit registers. interrupt request (abbreviated to int.req. in the figure) signals are all visible in the timer interrupt flag register (tifr0). all in terrupts are individually masked with the timer interrupt mask register (timsk0). tifr0 and timsk0 are not shown in the figure. the timer/counter can be clocked internally, via the prescaler, or by an external clock source on the t0 pin. the clock select logic block controls which clock source and edge the timer/counter uses to increment (or decrement) its value. the timer/counter is inactive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t0 ). the double buffered output compare registers (ocr0a and ocr0b) is compared with the timer/counter value at all times. the result of the compare can be used by the waveform generator to generate a pwm or variable frequency output on the output compare pins (oc0a and oc0b). see section 4.15.5 ?output compare unit? on page 79 for details. the compare match event will also set the compare flag (ocf0a or ocf0 b) which can be used to generate an output compare interrupt request. 4.15.2.2 definitions many register and bit references in this section are written in general form. a lower case ?n? replaces the timer/counter number, in this case 0. a lower case ?x? replaces the output com- pare unit, in this case compar e unit a or compare unit b. however, when using the register or bit defines in a program, the precise form must be used, i.e., tcnt0 for accessing timer/counter0 counter value and so on. the definitions in table 4-30 are also used extensively throughout the document. table 4-30. definitions 4.15.3 timer/counter clock sources the timer/counter can be clocked by an internal or an external clock source. the clock source is selected by the clock select logic wh ich is controlled by the clock select (cs02:0) bits located in the timer/counter control r egister (tccr0b). for details on clock sources and prescaler, see section 4.17 ?timer/counter prescaler? on page 123 . bottom the counter reaches the bottom when it becomes 0x00. max the counter reaches its maximum when it becomes 0xff (decimal 255). top the counter reaches the top when it becomes equal to the highest value in the count sequence. the top value can be assigned to be the fixed value 0xff (max) or the value stored in the ocr0a register. the assignment is dependent on the mode of operation.
78 9137e?rke?12/10 atmel ATA5771/73/74 4.15.4 counter unit the main part of the 8-bit timer/counter is the programmable bi-directional counter unit. table 4-27 shows a block diagram of the counter and its surroundings. figure 4-27. counter unit block diagram signal description (internal signals): count increment or decrement tcnt0 by 1. direction select between increment and decrement. clear clear tcnt0 (set all bits to zero). clk t n timer/counter clock, referred to as clk t0 in the following. top signalize that tcnt0 has reached maximum value. bottom signalize that tcnt0 has re ached minimum value (zero). depending of the mode of operation used, the counter is cleared, incremented, or decre- mented at each timer clock (clk t0 ). clk t0 can be generated from an external or internal clock source, selected by the clock select bits (c s02:0). when no clock source is selected (cs02:0 = 0) the timer is stopped. however, the tcnt0 value can be accessed by the cpu, regardless of whether clk t0 is present or not. a cpu write overrides (has priority over) all counter clear or count operations. the counting sequence is determined by the setting of the wgm01 and wgm00 bits located in the timer/counter control register (tccr0a) and the wgm02 bit located in the timer/counter control register b (tccr0b). t here are close connecti ons between how the counter behaves (counts) and how waveforms are generated on the output compare output oc0a. for more details about advanced counting sequences and waveform generation, see section 4.15.7 ?modes of operation? on page 81 . the timer/counter overflow flag (tov0) is set according to the mode of operation selected by the wgm01:0 bits. tov0 can be used for generating a cpu interrupt. data b u s tcntn control logic count tovn (int.req.) clock select top tn edge detector ( from prescaler ) clk tn bottom direction clear
79 9137e?rke?12/10 atmel ATA5771/73/74 4.15.5 output compare unit the 8-bit comparator continuously compares tcnt0 with the output compare registers (ocr0a and ocr0b). whenever tcnt0 equals ocr0a or ocr0b, the comparator signals a match. a match will set the output compare fl ag (ocf0a or ocf0b) at the next timer clock cycle. if the corresponding interrupt is enabled, the output compare flag generates an output compare interrupt. the output compare flag is automatically cleared when the interrupt is executed. alternatively, the flag can be cleared by software by writing a logical one to its i/o bit location. the waveform generator uses the match signal to generate an output according to operating mode set by the wgm02:0 bits and compare output mode (com0x1:0) bits. the max and bottom signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation. see section 4.15.7 ?modes of operation? on page 81 . figure 4-28 shows a block diagram of the output compare unit. figure 4-28. output compare unit, block diagram the ocr0x registers are double buffered when using any of the pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the double buffering is disabled. the double bufferi ng synchronizes the update of the ocr0x compare registers to either top or bottom of the counting sequence. the synchronization pre- vents the occurrence of odd-length, non-symme trical pwm pulses, thereby making the output glitch-free. the ocr0x register access may seem complex, but this is not case. when the double buffer- ing is enabled, the cpu has access to the ocr0x buffer register, and if double buffering is disabled the cpu will a ccess the ocr0x directly. ocfn x (int.req.) = (8-bit comparator ) ocrnx ocnx data b u s tcntn wgmn1:0 waveform generator top focn comnx1:0 bottom
80 9137e?rke?12/10 atmel ATA5771/73/74 4.15.5.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force output compare (0x) bit. forcing comp are match will not set the ocf0x flag or reload/clear the timer, but the oc0x pin will be updated as if a real compare match had occurred (the com0x1:0 bits settings define whether the oc0x pin is set, cleared or toggled). 4.15.5.2 compare match blocking by tcnt0 write all cpu write operations to the tcnt0 regist er will block any compare match that occur in the next timer clock cycle, even when the timer is stopped. this feature allows ocr0x to be initialized to the same value as tcnt0 without triggering an interrupt when the timer/counter clock is enabled. 4.15.5.3 using the output compare unit since writing tcnt0 in any m ode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing tcnt0 when using the output compare unit, independently of whether the timer/counter is running or not. if the value written to tcnt0 equals the ocr0x value, the compare match will be missed, resulting in incorrect waveform generation. similarly, do not write the tcnt0 value equal to bottom when the counter is down-counting. the setup of the oc0x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc0x value is to use the force output com- pare (0x) strobe bits in normal mode. the oc0x registers keep t heir values even when changing between waveform generation modes. be aware that the com0x1:0 bits are not double buffered together with the compare value. changing the com0x1:0 bits will take effect immediately. 4.15.6 compare match output unit the compare output mode (com0x1:0) bits have two functions. the waveform generator uses the com0x1:0 bits for defining the output compare (oc0x) state at the next compare match. also, the com0x1:0 bits control the oc0x pin output source. figure 4-29 on page 81 shows a simplified schematic of the logic affected by the com0x1:0 bit setting. the i/o regis- ters, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that are affe cted by the com0x1:0 bits are shown. when referring to the oc0x state, the reference is fo r the internal oc0x register, not the oc0x pin. if a system reset occur, the oc0x register is reset to ?0?.
81 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-29. compare match output unit, schematic the general i/o port function is overridden by the output compare (oc0x) from the waveform generator if either of the com0x1:0 bits are set. however, the oc0x pin direction (input or output) is still controlled by the data direction register (ddr ) for the port pin. the data direc- tion register bit for the oc0x pin (ddr_oc0x) must be set as output before the oc0x value is visible on the pin. the port override function is independent of the waveform generation mode. the design of the output compare pin logic allows initialization of the oc0x state before the output is enabled. note that some com0x1:0 bit settings are reserved for certain modes of operation, see section 4.10.8 ?register description? on page 44 4.15.6.1 compare output mode and waveform generation the waveform generator uses the com0x1:0 bi ts differently in normal, ctc, and pwm modes. for all modes, setting the com0x1:0 = 0 tells the waveform generator that no action on the oc0x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 4-31 on page 88 . for fast pwm mode, refer to table 4-32 on page 88 , and for phase correct pwm refer to table 4-33 on page 89 . a change of the com0x1:0 bits state will have effect at the first compare match after the bits are written. for non-pwm modes, the action can be forced to have immediate effect by using the 0x strobe bits. 4.15.7 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm02:0) and compare output mode (com0x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com0x1:0 bits control whether the pwm output generated should be inverted or not (inverted or non-inverted pwm). for non-pwm modes the com0x1:0 bits control whether the output should be set, cleared, or tog- gled at a compare match (see section 4.15.7 ?modes of operation? on page 81 ). port ddr dq dq ocn pin ocnx dq waveform generator comnx1 comnx0 0 1 data b u s focn clk i/o
82 9137e?rke?12/10 atmel ATA5771/73/74 for detailed timing information refer to figure 4-33 on page 86 , figure 4-34 on page 87 , fig- ure 4-35 on page 87 and figure 4-36 on page 87 in section 4.15.8 ?timer/counter timing diagrams? on page 86 . 4.15.7.1 normal mode the simplest mode of operation is the normal mode (wgm02:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 8-bit value (top = 0xff) and then restarts from the bot- tom (0x00). in normal operation the timer/counter overflow flag (tov0) will be set in the same timer clock cycle as the tcnt0 becomes zero . the tov0 flag in this case behaves like a ninth bit, except that it is only set, not cleared. however, combined with the timer overflow interrupt that automatically clears the tov0 flag, the timer resolution can be increased by software. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the output compare unit can be used to generate interrupts at some given time. using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the cpu time. 4.15.7.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm02:0 = 2), the ocr0a register is used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the coun- ter value (tcnt0) matches the ocr0a. the ocr0a defines the top value for the counter, hence also its resolution. this mode allows greater control of the compare match output fre- quency. it also simplifies the operati on of counting external events. the timing diagram for the ctc mode is shown in figure 4-30 . the counter value (tcnt0) increases until a compare match occurs between tcnt0 and ocr0a, and then counter (tcnt0) is cleared. figure 4-30. ctc mode, timing diagram an interrupt can be generated each time the counter value reaches the top value by using the ocf0a flag. if the interrupt is enabled, the interrupt handler routine can be used for updating the top value. however, changing top to a value close to bottom when the counter is running with none or a low prescaler value must be done with care since the ctc mode does not have the double buffering feature. if the new value written to ocr0a is lower than the current valu e of tcnt0, the counter will miss th e compare match. the counter will then have to count to its maximum value (0xff) and wrap around starting at 0x00 before the compare match can occur. tcntn ocn (toggle) ocnx interrupt flag set 1 4 period 2 3 (comnx1:0 = 1)
83 9137e?rke?12/10 atmel ATA5771/73/74 for generating a waveform output in ctc mode, the oc0a output can be set to toggle its log- ical level on each compare match by setting the compare output mode bits to toggle mode (com0a1:0 = 1). the oc0a value will not be visi ble on the port pin unless the data direction for the pin is set to output. the waveform generated will have a maximum frequency of 0 =f clk_i/o /2 when ocr0a is set to ze ro (0x00). the waveform frequency is defined by the fol- lowing equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). as for the normal mode of operation, the tov0 flag is set in the same timer clock cycle that the counter counts from max to 0x00. 4.15.7.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm02:0 = 3 or 7) provides a high fre- quency pwm waveform generation option. the fast pwm differs from the other pwm option by its single-slope operation. t he counter counts from bottom to top then restarts from bottom. top is defined as 0xff when wgm2:0 = 3, and ocr0a when wgm2:0 = 7. in non-inverting compare output mode, the output compare (oc0x) is cleared on the compare match between tcnt0 and ocr0x, and set at bottom. in inverting compare output mode, the output is set on compare match and cleared at bottom. due to the single-slope opera- tion, the operating frequency of the fast pwm mo de can be twice as high as the phase correct pwm mode that use dual-slope operation. th is high frequency makes the fast pwm mode well suited for power regulation, rectificat ion, and dac applications. high frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. in fast pwm mode, the counter is incremented until the counter value matches the top value. the counter is then cleared at the following ti mer clock cycle. the timing diagram for the fast pwm mode is shown in figure 4-31 . the tcnt0 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt0 slopes represent com- pare matches between ocr0x and tcnt0. f ocnx f clk_i/o 2 n 1 ocrnx + () ?? ------------------------------------------------------- =
84 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-31. fast pwm mode, timing diagram the timer/counter overflow flag (tov0) is se t each time the counter reaches top. if the interrupt is enabled, the interrupt handler routine can be used for updating the compare value. in fast pwm mode, the compare unit allows generation of pwm waveforms on the oc0x pins. setting the com0x1:0 bits to two will produce a non-inverted pwm and an inverted pwm out- put can be generated by setting the com0x1:0 to three: setting the com0a1:0 bits to one allowes the ac0a pin to toggle on compare matches if the wgm02 bit is set. this option is not available for the oc0b pin (see table 4-32 on page 88 ). the actual oc0x value will only be visible on the port pin if the data direction for the port pin is set as output. the pwm waveform is generated by setting (or clearing) the oc 0x register at the compare match between ocr0x and tcnt0, and clearing (or setting) the oc0x register at the timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). the extreme values for the ocr0a register represents special cases when generating a pwm waveform output in the fast pwm mode. if the ocr0a is set equal to bottom, the out- put will be a narrow spike for each max+1 time r clock cycle. setting th e ocr0a equal to max will result in a constantly high or low output (d epending on the polarity of the output set by the com0a1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by setting oc0x to toggle its logical level on each compare match (com0x1:0 = 1). the wave- form generated will have a maximum frequency of 0 = f clk_i/o /2 when ocr0a is set to zero. this feature is similar to the oc0a toggle in ctc mode, except the double buffer feature of the output compare unit is enabled in the fast pwm mode. tcntn ocrnx update and tovn interrupt flag set 1 period 2 3 ocn ocn (comnx1:0 = 2) (comnx1:0 = 3) ocrnx interrupt flag set 4 5 6 7 f ocnxpwm f clk_i/o n 256 ? -------------------- - =
85 9137e?rke?12/10 atmel ATA5771/73/74 4.15.7.4 phase correct pwm mode the phase correct pwm mode (wgm02:0 = 1 or 5) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is based on a dual-slope operation. the counter counts repeatedly from bottom to top and then from top to bot- tom. top is defined as 0xff when wgm2:0 = 1, and ocr0a when wgm2:0 = 5. in non-inverting compare output mode, the output compare (oc0x) is cleared on the compare match between tcnt0 and ocr0x while upcounting, and set on the compare match while down-counting. in inverting output compare mode, the operation is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the symmetric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. in phase correct pwm mode the counter is incremented until the counter value matches top. when the counter reaches top, it changes th e count direction. the tcnt0 value will be equal to top for one timer clock cycle. the ti ming diagram for the phase correct pwm mode is shown on figure 4-32 on page 85 . the tcnt0 value is in the timing diagram shown as a histogram for illustrating the dua l-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt0 slopes represent com- pare matches between ocr0x and tcnt0. figure 4-32. phase correct pwm mode, timing diagram the timer/counter overflow flag (tov0) is set each time the counter reaches bottom. the interrupt flag can be used to generate an interrupt each time the counter reaches the bot- tom value. in phase correct pwm mode, the compare unit allows generation of pwm waveforms on the oc0x pins. setting the com0x1:0 bits to two will produce a non-inverted pwm. an inverted pwm output can be generated by setting the com0x1:0 to three: setting the com0a0 bits to one allows the oc0a pin to toggle on compare matches if the wgm02 bit is set. this option is not available for the oc0b pin (see table 4-33 on page 89 ). the actual oc 0x value will only be visible on the port pin if the data direction for the port pin is set as output. tovn interrupt flag set ocnx interrupt flag set 1 2 3 tcntn period ocn ocn (comnx1:0 = 2) (comnx1:0 = 3) ocrnx update
86 9137e?rke?12/10 atmel ATA5771/73/74 the pwm waveform is generated by clearing (or setting) the oc0x register at the compare match between ocr0x and tcnt0 when the counter increments, and setting (or clearing) the oc0x register at compare match between ocr0x and tcnt0 when the counter decre- ments. the pwm frequency for the output when using phase correct pwm can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). the extreme values for the ocr0a register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr0a is set equal to bottom, the output will be continuously low an d if set equal to max the out put will be continuously high for non-inverted pwm mode. for in verted pwm the output will have the opposite logic values. at the very start of period 2 in figure 4-32 on page 85 ocn has a transition from high to low even though there is no compare match. the point of this transition is to guaratee symmetry around bottom. there are two cases that give a transition without compare match. ? ocr0a changes its value from max, like in figure 4-32 on page 85 . when the ocr0a value is max the ocn pin value is the same as the result of a down-counting compare match. to ensure symmetry around bottom the ocn value at max must correspond to the result of an up-counting compare match. ? the timer starts counting from a value higher than the one in ocr0a, and for that reason misses the compare match and hence the ocn change that would have happened on the way up. 4.15.8 timer/counter timing diagrams the timer/counter is a synchronous design and the timer clock (clk t0 ) is therefore shown as a clock enable signal in the follow ing figures. the figures include information on when interrupt flags are set. figure 4-33 contains timing data for basic timer/counter operation. the figure shows the count sequence close to the max value in all modes other than phase correct pwm mode. figure 4-33. timer/counter timing diagram, no prescaling f ocnxpcpwm f clk_i/o n 510 ? -------------------- - = clk tn (clk i/o /1) tovn clk i/o tcntn max - 1 max bottom bottom + 1
87 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-34 shows the same timing data, but with the prescaler enabled. figure 4-34. timer/counter timing dia gram, with prescaler (f clk_i/o /8) figure 4-35 shows the setting of ocf0b in all modes and ocf0a in all modes except ctc mode and pwm mode, where ocr0a is top. figure 4-35. timer/counter timing diagram, setting of ocf0x, with prescaler (f clk_i/o /8) figure 4-36 shows the setting of ocf0a and the clearing of tcnt0 in ctc mode and fast pwm mode where ocr0a is top. figure 4-36. timer/counter timing diagram, clear timer on compare match mode, with prescaler (f clk_i/o /8) tovn tcntn max - 1 max bottom bottom + 1 clk i/o clk tn (clk i/o /8) ocfnx ocrnx tcntn ocrnx value ocrnx - 1 ocrnx ocrnx + 1 ocrnx + 2 clk i/o clk tn (clk i/o /8) ocfnx ocrnx tcntn (ctc) top top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o /8)
88 9137e?rke?12/10 atmel ATA5771/73/74 4.15.9 register description 4.15.9.1 tccr0a ? timer/counter control register a ? bits 7:6 ? com0a1:0: compare match output a mode these bits control the output compare pin (oc0a) behavior. if one or both of the com0a1:0 bits are set, the oc0a output overrides the normal port functionality of the i/o pin it is con- nected to. however, note that the data direction register (ddr) bit corresponding to the oc0a pin must be set in order to enable the output driver. when oc0a is connected to the pin, the func tion of the com0a1:0 bits depends on the wgm02:0 bit setting. table 4-31 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to a normal or ctc mode (non-pwm). table 4-32 shows the com0a1:0 bit functionality when the wgm01:0 bits are set to fast pwm mode. note: 1. a special case occurs when ocr0a equals top and com0a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see section 4.15.7.3 ?fast pwm mode? on page 83 for more details. bit 7 6 5 4 3 2 1 0 0x30 (0x50) com0a1 com0a0 com0b1 com0b0 ? ? wgm01 wgm00 tccr0a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 table 4-31. compare output mode, non-pwm mode com01 com00 description 0 0 normal port operation, oc0a disconnected. 0 1 toggle oc0a on compare match 1 0 clear oc0a on compare match 1 1 set oc0a on compare match table 4-32. compare output mode, fast pwm mode (1) com01 com00 description 0 0 normal port operation, oc0a disconnected. 01 wgm02 = 0: normal port oper ation, oc0a disconnected. wgm02 = 1: toggle oc0a on compare match. 10 clear oc0a on compare match, set oc0a at bottom (non-inverting mode) 11 set oc0a on compare match, clear oc0a at bottom (inverting mode)
89 9137e?rke?12/10 atmel ATA5771/73/74 table 4-33 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to phase correct pwm mode. note: 1. a special case occurs when ocr0a equals top and com0a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see section 4.15.7.4 ?phase correct pwm mode? on page 85 for more details. ? bits 5:4 ? com0b1:0: compare match output b mode these bits control the output compare pin (oc0b) behavior. if one or both of the com0b1:0 bits are set, the oc0b output overrides the normal port functionality of the i/o pin it is con- nected to. however, note that the data direction register (ddr) bit corresponding to the oc0b pin must be set in order to enable the output driver. when oc0b is connected to the pin, the func tion of the com0b1:0 bits depends on the wgm02:0 bit setting. table 4-34 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to a normal or ctc mode (non-pwm). table 4-35 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to fast pwm mode. note: 1. a special case occurs when ocr0b equals top and com0b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see section 4.15.7.3 ?fast pwm mode? on page 83 for more details. table 4-33. compare output mode, phase correct pwm mode (1) com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected. 01 wgm02 = 0: normal port operation, oc0a disconnected. wgm02 = 1: toggle oc0a on compare match. 10 clear oc0a on compare match when up-counting. set oc0a on compare match when down-counting. 11 set oc0a on compare match when up-counting. clear oc0a on compare match when down-counting. table 4-34. compare output mode, non-pwm mode com01 com00 description 0 0 normal port operation, oc0b disconnected. 0 1 toggle oc0b on compare match 1 0 clear oc0b on compare match 1 1 set oc0b on compare match table 4-35. compare output mode, fast pwm mode (1) com01 com00 description 0 0 normal port operation, oc0b disconnected. 01reserved 10 clear oc0b on compare match, set oc0b at bottom (non-inverting mode) 11 set oc0b on compare match, clear oc0b at bottom (inverting mode)
90 9137e?rke?12/10 atmel ATA5771/73/74 table 4-36 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to phase correct pwm mode. note: 1. a special case occurs when ocr0b equals top and com0b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see section 4.15.7.4 ?phase correct pwm mode? on page 85 for more details. ? bits 3, 2 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bits 1:0 ? wgm01:0: waveform generation mode combined with the wgm02 bit found in the t ccr0b register, these bits control the counting sequence of the counter, the source for maximum (top) counter value, and what type of waveform generation to be used, see table 4-37 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and two types of pulse width modulation (pwm) modes (see section 4.15.7 ?modes of oper- ation? on page 81 ). note: 1. max = 0xff bottom = 0x00 table 4-36. compare output mode, phase correct pwm mode (1) com0a1 com0a0 description 0 0 normal port operation, oc0b disconnected. 01reserved 10 clear oc0b on compare match when up-counting. set oc0b on compare match when down-counting. 11 set oc0b on compare match when up-counting. clear oc0b on compare match when down-counting. table 4-37. waveform generation mode bit description mode wgm2 wgm1 wgm0 timer/counter mode of operation top update of ocrx at tov flag set on (1) 0 0 0 0 normal 0xff immediate max 1001 pwm, phase correct 0xff top bottom 2 0 1 0 ctc ocra immediate max 3 0 1 1 fast pwm 0xff bottom max 4100reserved ? ? ? 5101 pwm, phase correct ocra top bottom 6110reserved ? ? ? 7 1 1 1 fast pwm ocra bottom top
91 9137e?rke?12/10 atmel ATA5771/73/74 4.15.9.2 tccr0b ? timer/counter control register b ? bit 7 ? foc0a: force output compare a the foc0a bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibi lity with future devices, this bit must be set to zero when tccr0b is written when operating in pwm mode. when writing a logical one to the foc0a bit, an immediate compare match is forced on the waveform generation unit. the oc0a out- put is changed according to its com0a1:0 bits setting. note that the foc0a bit is implemented as a strobe. therefore it is the value present in the com0a1:0 bits that deter- mines the effect of the forced compare. a foc0a strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr0a as top. the foc0a bit is always read as zero. ? bit 6 ? foc0b: force output compare b the foc0b bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibi lity with future devices, this bit must be set to zero when tccr0b is written when operating in pwm mode. when writing a logical one to the foc0b bit, an immediate compare match is forced on the waveform generation unit. the oc0b out- put is changed according to its com0b1:0 bits setting. note that the foc0b bit is implemented as a strobe. therefore it is the value present in the com0b1:0 bits that deter- mines the effect of the forced compare. a foc0b strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr0b as top. the foc0b bit is always read as zero. ? bits 5:4 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 3 ? wgm02: waveform generation mode see the description in the section 4.15.9.1 ?tccr0a ? timer/counter control register a? on page 88 . ? bits 2:0 ? cs02:0: clock select the three clock select bits select the clock source to be used by the timer/counter. bit 7 6 5 4 3 2 1 0 0x33 (0x55) foc0a foc0b ? ? wgm02 cs02 cs01 cs00 tccr0b read/write w w r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
92 9137e?rke?12/10 atmel ATA5771/73/74 if external pin modes are used for the timer/c ounter0, transitions on the t0 pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 4.15.9.3 tcnt0 ? timer/counter register the timer/counter register gives direct access, both for read and write operations, to the timer/counter unit 8-bit counter. writing to t he tcnt0 register blocks (removes) the com- pare match on the following timer clock. modify ing the counter (tcnt0) while the counter is running, introduces a risk of missing a compare match between tcnt0 and the ocr0x registers. 4.15.9.4 ocr0a ? output compare register a the output compare register a contains an 8-bit value that is continuously compared with the counter value (tcnt0). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc0a pin. 4.15.9.5 ocr0b ? output compare register b the output compare register b contains an 8-bit value that is continuously compared with the counter value (tcnt0). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc0b pin. table 4-38. clock select bit description cs02 cs01 cs00 description 0 0 0 no clock source (timer/counter stopped) 001clk i/o /(no prescaling) 010clk i/o /8 (from prescaler) 011clk i/o /64 (from prescaler) 100clk i/o /256 (from prescaler) 101clk i/o /1024 (from prescaler) 1 1 0 external clock source on t0 pin. clock on falling edge. 1 1 1 external clock source on t0 pin. clock on rising edge. bit 76543210 0x32 (0x52) tcnt0[7:0] tcnt0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x36 (0x56) ocr0a[7:0] ocr0a read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x3c (0x5c) ocr0b[7:0] ocr0b read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
93 9137e?rke?12/10 atmel ATA5771/73/74 4.15.9.6 timsk 0 ? timer/counter 0 interrupt mask register ? bits 7..3 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 2? ocie0b: timer/counter output compare match b interrupt enable when the ocie0b bit is written to one, and the i-bit in the status register is set, the timer/counter compare match b interrupt is enab led. the corresponding interrupt is executed if a compare match in timer/counter occurs , i.e., when the ocf0b bit is set in the timer/counter interrupt flag register ? tifr0. ? bit 1? ocie0a: timer/counter0 output compare match a interrupt enable when the ocie0a bit is written to one, and the i-bit in the status register is set, the timer/counter0 compare match a interrupt is enabled. the corresponding interrupt is exe- cuted if a compare match in timer/counter0 occurs, i.e., when the ocf0a bit is set in the timer/counter 0 interrupt flag register ? tifr0. ? bit 0? toie0: timer/counter0 overflow interrupt enable when the toie0 bit is written to one, and the i-bit in the status register is set, the timer/counter0 overflow interrupt is enabled. the corresponding interrupt is executed if an overflow in timer/counter0 occurs, i.e., when th e tov0 bit is set in the timer/counter 0 inter- rupt flag register ? tifr0. 4.15.9.7 tifr 0 ? timer/counter 0 interrupt flag register ? bits 7..3 ? res: reserved bits these bits are reserved bits in the attiny44v and will always read as zero. ? bit 2? ocf0b: output compare flag 0 b the ocf0b bit is set when a compare match occurs between the timer/counter and the data in ocr0b ? output compare register0 b. ocf0b is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, ocf0b is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie0b (timer/counter compare b match interrupt enable), and ocf0b are set, the timer/counter compare match interrupt is executed. ? bit 1? ocf0a: output compare flag 0 a the ocf0a bit is set when a compare match occurs between the timer/counter0 and the data in ocr0a ? output compare register0. ocf0a is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, ocf0a is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie0a (timer/counter0 compare match interrupt enable), and ocf0a are set, the timer/counter0 compare match interrupt is executed. bit 76543 2 10 0x39 (0x59) ? ? ? ? ? ocie0b ocie0a toie0 timsk0 read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x38 (0x58) ?????ocf0bocf0atov0tifr0 read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
94 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 0? tov0: timer/counter0 overflow flag the bit tov0 is set when an overflow occurs in timer/counter0. tov0 is cleared by hardware when executing the corresponding interrupt hand ling vector. alternatively, tov0 is cleared by writing a logic one to the flag. when the sreg i-bit, toie0 (timer/counter0 overflow interrupt enable), and tov0 are set, the timer/counter0 overflow interrupt is executed. the setting of this flag is dependent of the wgm02:0 bit setting. see table 4-37 on page 90 . 4.16 16-bit timer/counter1 4.16.1 features ? true 16-bit design (i.e., allows 16-bit pwm) ? two independent output compare units ? double buffered outp ut compare registers ? one input capture unit ? input capture noise canceler ? clear timer on compare match (auto reload) ? glitch-free, phase correct pu lse width modulator (pwm) ? variable pwm period ? frequency generator ? external event counter ? four independent interrupt sources (tov1, ocf1a, ocf1b, and icf1) 4.16.2 overview the 16-bit timer/counter unit allows accurate program execution timing (event management), wave generation, and signal timing measurement. most register and bit references in this section are written in general form. a lower case ?n? replaces the timer/counter number, and a lower case ?x? replaces the output compare unit channel. however, when using the register or bit defines in a program, the precise form must be used, i.e., tcnt1 for accessing timer/counter1 counter value and so on. a simplified block diagram of the 16-bit timer/counter is shown in figure 4-37 on page 95 . for the actual placement of i/o pins. cpu accessible i/o registers, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit locations are listed in the section 4.8.5 ?register description? on page 29 .
95 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-37. 16-bit timer/counter block diagram 4.16.2.1 registers the timer/counter (tcnt1), output compare registers (ocr1a/b), and input capture reg- ister (icr1) are all 16-bit registers. special pr ocedures must be followed when accessing the 16-bit registers. these procedures are described in the section section 4.16.3 ?accessing 16-bit registers? on page 97 . the timer/counter control registers (tccr1a/b) are 8-bit reg- isters and have no cpu access restrictions. inte rrupt requests (abbreviated to int.req. in the figure) signals are all visible in the timer interrupt flag register (tifr). all interrupts are indi- vidually masked with the timer interrupt mask register (timsk). tifr and timsk are not shown in the figure. the timer/counter can be clocked internally, via the prescaler, or by an external clock source on the t1 pin. the clock select logic block controls which clock source and edge the timer/counter uses to increment (or decrement) its value. the timer/counter is inactive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t 1 ). clock select timer/counter data b u s ocrna ocrnb icrn = = tcntn waveform generation waveform generation ocna ocnb noise canceler icpn = fixed top values edge detector control logic = 0 top bottom count clear direction tovn (int.req.) ocna (int.req.) ocnb (int.req.) icfn (int.req.) tccrna tccrnb ( from analog comparator ouput ) tn edge detector ( from prescaler ) clk tn
96 9137e?rke?12/10 atmel ATA5771/73/74 the double buffered output compare registers (ocr1a/b) are compared with the timer/counter value at all time. the result of the compare can be used by the waveform gen- erator to generate a pwm or variable frequency output on the output compare pin (oc1a/b). see section 4.15.5 ?output compare unit? on page 79 . the compare match event will also set the compare match flag (ocf1a/b) which can be used to generate an output compare inter- rupt request. the input capture register can capture the ti mer/counter value at a given external (edge triggered) event on either the input capture pin (icp1) or on the analog comparator pins (see section 4.19 ?analog comparator? on page 137 ). the input capture unit includes a digital fil- tering unit (noise canceler) for reducing the chance of capturing noise spikes. the top value, or maximum timer/counter value, can in some modes of operation be defined by either the ocr1a register, the icr1 register, or by a set of fixed values. when using ocr1a as top value in a pwm mode, the ocr1a register can not be used for gener- ating a pwm output. however, the top value will in this case be double buffered allowing the top value to be changed in run time. if a fixed top value is required, the icr1 register can be used as an alternative, freeing the ocr1a to be used as pwm output. 4.16.2.2 definitions the following definitions are used extensively throughout the section: 4.16.2.3 compatibility the 16-bit timer/counter has been updated and improved from previous versions of the 16-bit avr ? timer/counter. this 16-bit timer/counter is fully compatible with the earlier version regarding: ? all 16-bit timer/counter related i/o register address locations, including timer interrupt registers. ? bit locations inside all 16-bit timer/counter registers, including timer interrupt registers. ? interrupt vectors. the following control bits have changed name, but have same functionality and register location: ? pwm10 is changed to wgm10. ? pwm11 is changed to wgm11. ? ctc1 is changed to wgm12. the following bits are added to the 16-bit timer/counter control registers: ? 1a and 1b are added to tccr1a. ? wgm13 is added to tccr1b. the 16-bit timer/counter has im provements that will affect the compatibility in some special cases. bottom the counter reaches the bottom when it becomes 0x0000. max the counter reaches its max imum when it becomes 0xffff (decimal 65535). top the counter reaches the top when it becomes equal to the highest value in the count sequence. the top value can be assigned to be one of the fixed values: 0x00ff, 0x01ff, or 0x03ff, or to the value stored in the ocr1a or icr1 register. the assign- ment is dependent of the mode of operation.
97 9137e?rke?12/10 atmel ATA5771/73/74 4.16.3 accessing 16-bit registers the tcnt1, ocr1a/b, and icr1 are 16-bit registers that can be accessed by the avr ? cpu via the 8-bit data bus. the 16-bit register must be byte accessed using two read or write oper- ations. each 16-bit timer has a single 8-bit register for temporary storing of the high byte of the 16-bit access. the same temporary register is shared between all 16-bit registers within each 16-bit timer. accessing the low byte triggers the 16-bit read or write operation. when the low byte of a 16-bit register is written by the cpu, the high byte stored in the temporary register, and the low byte written are both copied into the 16-bit register in the same clock cycle. when the low byte of a 16-bit register is read by the cpu, the high byte of the 16-bit register is cop- ied into the temporary register in the same clock cycle as the low byte is read. not all 16-bit accesses uses the temporary register for the high byte. reading the ocr1a/b 16-bit registers does not involve using the temporary register. to do a 16-bit write, the high byte must be written before the low byte. for a 16-bit read, the low byte must be read before the high byte. the following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. the same principle can be used directly for access- ing the ocr1a/b and icr1 registers. note t hat when using ?c?, the compiler handles the 16-bit access. note: 1. see section 4.6 ?about code examples? on page 13 . the assembly code example returns the tcnt1 value in the r17:r16 register pair. assembly code examples (1) ... ; set tcnt 1 to 0x01ff ldi r17,0x01 ldi r16,0xff out tcnt 1 h,r17 out tcnt 1 l,r16 ; read tcnt 1 into r17:r16 in r16,tcnt 1 l in r17,tcnt 1 h ... c code examples (1) unsigned int i; ... /* set tcnt 1 to 0x01ff */ tcnt 1 = 0x1ff; /* read tcnt 1 into i */ i = tcnt 1 ; ...
98 9137e?rke?12/10 atmel ATA5771/73/74 it is important to notice that accessing 16-bit registers are atomic operations. if an interrupt occurs between the two instructions accessi ng the 16-bit register, and the interrupt code updates the temporary register by accessing the same or any other of the 16-bit timer regis- ters, then the result of the ac cess outside the interr upt will be corrupted. therefore, when both the main code and the interrupt code update the temporary register, the main code must dis- able the interrupts during the 16-bit access. the following code examples show how to do an atomic read of the tcnt1 register contents. reading any of the ocr1a/b or icr1 registers can be done by using the same principle. note: 1. see section 4.6 ?about code examples? on page 13 . the assembly code example returns the tcnt1 value in the r17:r16 register pair. assembly code example (1) tim16_readtcnt 1 : ; save global interrupt flag in r18,sreg ; disable interrupts cli ; read tcnt 1 into r17:r16 in r16,tcnt 1 l in r17,tcnt 1 h ; restore global interrupt flag out sreg,r18 ret c code example (1) unsigned int tim16_readtcnt 1 ( void ) { unsigned char sreg; unsigned int i; /* save global interrupt flag */ sreg = sreg; /* disable interrupts */ _cli(); /* read tcnt 1 into i */ i = tcnt 1 ; /* restore global interrupt flag */ sreg = sreg; return i; }
99 9137e?rke?12/10 atmel ATA5771/73/74 the following code examples show how to do an atomic write of the tcnt1 register contents. writing any of the ocr1a/b or icr1 register s can be done by using the same principle. note: 1. see section 4.6 ?about code examples? on page 13 . the assembly code example requires that the r17:r16 register pair contains the value to be written to tcnt1. 4.16.3.1 reusing the temporary high byte register if writing to more than one 16-bit register where the high byte is the same for all registers writ- ten, then the high byte only needs to be written once. however, note that the same rule of atomic operation described previously also applies in this case. 4.16.4 timer/counter clock sources the timer/counter can be clocked by an internal or an external clock source. the clock source is selected by the clock select logic which is controlled by the clock select (cs12:0) bits located in the timer/counter control register b (tccr1b). for detail s on clock sources and prescaler, see section 4.17 ?timer/counter prescaler? on page 123 . assembly code example (1) tim16_writetcnt 1 : ; save global interrupt flag in r18,sreg ; disable interrupts cli ; set tcnt 1 to r17:r16 out tcnt 1 h,r17 out tcnt 1 l,r16 ; restore global interrupt flag out sreg,r18 ret c code example (1) void tim16_writetcnt 1 ( unsigned int i ) { unsigned char sreg; unsigned int i; /* save global interrupt flag */ sreg = sreg; /* disable interrupts */ _cli(); /* set tcnt 1 to i */ tcnt 1 = i; /* restore global interrupt flag */ sreg = sreg; }
100 9137e?rke?12/10 atmel ATA5771/73/74 4.16.5 counter unit the main part of the 16-bit timer/counter is the programmable 16-bit bi-directional counter unit. figure 4-38 shows a block diagram of the counter and its surroundings. figure 4-38. counter unit block diagram signal description (internal signals): count increment or decrement tcnt1 by 1. direction select between increment and decrement. clear clear tcnt1 (set all bits to zero). clk t 1 timer/counter clock. top signalize that tcnt1 has reached maximum value. bottom signalize that tcnt1 has re ached minimum value (zero). the 16-bit counter is mapped into two 8-bit i/o memory locations: counter high (tcnt1h) containing the upper eight bits of the counter, and counter low (tcnt1l) containing the lower eight bits. the tcnt1h register can only be indirectly accessed by the cpu. when the cpu does an access to the tcnt1h i/o location, t he cpu accesses the high byte temporary regis- ter (temp). the temporary register is updated with the tcnt1h value when the tcnt1l is read, and tcnt1h is updated with the temporary register value when tcnt1l is written. this allows the cpu to read or write the entire 16 -bit counter value within one clock cycle via the 8-bit data bus. it is important to notice that there are special cases of writing to the tcnt1 register when the counter is counting that will give unpredictable resu lts. the special cases are described in the sections where they are of importance. depending on the mode of operation used, the counter is cleared, incremented, or decre- mented at each timer clock (clk t 1 ). the clk t 1 can be generated from an external or internal clock source, selected by the clock select bits (cs12:0). when no clock source is selected (cs12:0 = 0) the timer is stopped. however, the tcnt1 value can be accessed by the cpu, independent of whether clk t 1 is present or not. a cpu write overrides (has priority over) all counter clear or count operations. the counting sequence is determined by the setting of the waveform generation mode bits (wgm13:0) located in the timer/counter control registers a and b (tccr1a and tccr1b). there are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs oc1x. for more details about advanced count- ing sequences and wave form generation, see section 4.15.7 ?modes of operation? on page 81 . the timer/counter overflow flag (tov1) is set according to the mode of operation selected by the wgm13:0 bits. tov1 can be used for generating a cpu interrupt. temp (8-bit) data bus (8-bit) tcntn (16-bit counter) tcntnh (8-bit) tcntnl (8-bit) control logic count clear direction tovn (int.req.) clock select top bottom tn edge detector ( from prescaler ) clk tn
101 9137e?rke?12/10 atmel ATA5771/73/74 4.16.6 input capture unit the timer/counter incorporates an input capture unit that can capture external events and give them a time-stamp indicating time of occurrence. the external signal indicating an event, or multiple events, can be applied via the icp1 pin or alternatively, via the analog-comparator unit. the time-stamps can then be used to ca lculate frequency, duty-cycle, and other features of the signal applied. alternatively the time-stamps can be used for creating a log of the events. the input capture unit is illustrated by the block diagram shown in figure 4-39 . the elements of the block diagram that are not directly a part of the input capture unit are gray shaded. the small ?n? in register and bit names indicates the timer/counter number. figure 4-39. input capture unit block diagram when a change of the logic level (an event) occurs on the input capture pin (icp1), alterna- tively on the analog comparator output (aco), and this change confirms to the setting of the edge detector, a capture will be tr iggered. when a captur e is triggered, the 16-bit value of the counter (tcnt1) is written to the input capture register (icr1). the input capture flag (icf1) is set at the same system clock as th e tcnt1 value is copied into icr1 register. if enabled (icie1 = 1), the input capture flag generates an input capture interrupt. the icf1 flag is automatically cleared when the interrupt is executed. alternatively the icf1 flag can be cleared by software by writing a logical one to its i/o bit location. reading the 16-bit value in the input capture register (icr1) is done by first reading the low byte (icr1l) and then the high byte (icr1h). when the low byte is read the high byte is cop- ied into the high byte temporary register (temp). when the cpu reads the icr1h i/o location it will access the temp register. icfn (int.req.) analog comparator write icrn (16-bit register) icrnh (8-bit) noise canceler icpn edge detector temp (8-bit) data bus (8-bit) icrnl (8-bit) tcntn (16-bit counter) tcntnh (8-bit) tcntnl (8-bit) acic* icnc ices aco*
102 9137e?rke?12/10 atmel ATA5771/73/74 the icr1 register can only be written when using a waveform generat ion mode that utilizes the icr1 register for defining the counter?s top value. in these cases the waveform genera- tion mode (wgm13:0) bits must be set before the top value can be written to the icr1 register. when writing the icr1 register the high byte must be written to the icr1h i/o loca- tion before the low byte is written to icr1l. for more information on how to access the 16-bit registers refer to section 4.16.3 ?accessing 16-bit registers? on page 97 . 4.16.6.1 input capture trigger source the main trigger source for the input capture unit is the input capture pin (icp1). timer/counter1 can alternatively use the analog comparator output as trigger source for the input capture unit. the analog comparator is selected as trigger source by setting the analog comparator input capture (acic) bit in the analog comparator control and status register (acsr). be aware that changing trigger source can trigger a capture. the input capture flag must therefore be cleared after the change. both the input capture pin (icp1) and the analog comparator output (aco) inputs are sam- pled using the same technique as for the t1 pin ( figure 4-50 on page 123 ). the edge detector is also identical. however, when the noise canceler is enabled, additional logic is inserted before the edge detector, which increases the delay by four system clock cycles. note that the input of the noise canceler and edge detector is always enabled unless the timer/counter is set in a waveform generation mode that uses icr1 to define top. an input capture can be triggered by softwar e by controlling the port of the icp1 pin. 4.16.6.2 noise canceler the noise canceler improves noise immunity by using a simple digital filtering scheme. the noise canceler input is monitored over four samples, and all four must be equal for changing the output that in turn is used by the edge detector. the noise canceler is enabled by setting the input capture noise canceler (icnc1) bit in timer/counter control register b (tccr1b). when enabled the noise canceler introduces additional four system clock cycles of delay fr om a change applied to the input, to the update of the icr1 register. the noise canceler uses the system clock and is therefore not affected by the prescaler. 4.16.6.3 using the input capture unit the main challenge when using the input capture unit is to assign enough processor capacity for handling the incoming events. the time betwee n two events is critical. if the processor has not read the captured value in the icr1 regist er before the next ev ent occurs, the icr1 will be overwritten with a new valu e. in this case the result of the capture will be incorrect. when using the input capture interrupt, the icr1 register should be read as early in the inter- rupt handler routine as possible. even though t he input capture interrupt has relatively high priority, the maximum interrupt response time is dependent on the maximum number of clock cycles it takes to handle any of the other interrupt requests. using the input capture unit in any mode of operation when the top value (resolution) is actively changed during operation, is not recommended.
103 9137e?rke?12/10 atmel ATA5771/73/74 measurement of an external signal?s duty cycle requires that the trigger edge is changed after each capture. changing the e dge sensing must be done as early as possible after the icr1 register has been read. after a change of the edge, the input capture flag (icf1) must be cleared by software (writing a logical one to the i/o bit location). for measuring frequency only, the clearing of the icf1 flag is not required (if an interrupt handler is used). 4.16.7 output compare units the 16-bit comparator continuously compares tcnt1 with the output compare register (ocr1x). if tcnt equals ocr1x the compar ator signals a match. a match will set the output compare flag (ocf1x) at the next timer clock cycle. if enabled (ocie1x = 1), the output compare flag generates an output compare interrupt. the ocf1x flag is automatically cleared when the interrupt is executed. alternat ively the ocf1x flag can be cleared by soft- ware by writing a logical one to its i/o bit location. the waveform generator uses the match signal to generate an output according to operating mode set by the waveform generation mode (wgm13:0) bits and compare output mode (com1x1:0) bits. the top and bottom signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation ( section 4.15.7 ?modes of operation? on page 81 ). a special feature of output compare unit a allows it to define the timer/counter top value (i.e., counter resolution). in addition to the counter resolution, the top value defines the period time for waveforms generated by the waveform generator. figure 4-40 shows a block diagram of the output compare unit. the small ?n? in the register and bit names indicates the device number (n = 1 for timer/counter 1), and the ?x? indicates output compare unit (a/b). the elements of the block diagram that are not directly a part of the output compare unit are gray shaded. figure 4-40. output compare unit, block diagram ocfnx (int.req.) = (16-bit comparator ) ocrnx buffer (16-bit register) ocrnxh buf. (8-bit) ocnx temp (8-bit) data bus (8-bit) ocrnxl buf. (8-bit) tcntn (16-bit counter) tcntnh (8-bit) tcntnl (8-bit) comnx1:0 wgmn3:0 ocrnx (16-bit register) ocrnxh (8-bit) ocrnxl (8-bit) waveform generator top bottom
104 9137e?rke?12/10 atmel ATA5771/73/74 the ocr1x register is double buffered when using any of the twelve pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the double buffering is disabled. the double bufferi ng synchronizes the update of the ocr1x compare register to either top or bottom of the counting sequenc e. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm pulses, thereby making the out- put glitch-free. the ocr1x register access may seem complex, but this is not case. when the double buffer- ing is enabled, the cpu has access to the ocr1x buffer register, and if double buffering is disabled the cpu will access the ocr1x direct ly. the content of the ocr1x (buffer or com- pare) register is only changed by a write operation (the timer/counter does not update this register automatically as the tcnt1 and icr1 register). therefore ocr1x is not read via the high byte temporary register (temp). however, it is a good practice to read the low byte first as when accessing other 16-bit registers. wr iting the ocr1x registers must be done via the temp register since the compare of all 16 bits is done continuously. the high byte (ocr1xh) has to be written first. when the high byte i/o lo cation is written by the cpu, the temp regis- ter will be updated by the value written. then w hen the low byte (ocr1xl) is written to the lower eight bits, the high byte will be copied into the upper 8-bits of ei ther the o cr1x buffer or ocr1x compare register in the same system clock cycle. for more information of how to access the 16-bit registers refer to section 4.16.3 ?accessing 16-bit registers? on page 97 . 4.16.7.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force output compare (1x) bit. forcing comp are match will not set the ocf1x flag or reload/clear the timer, but the oc1x pin will be updated as if a real compare match had occurred (the com11:0 bits settings define whether the oc1x pin is set, cleared or toggled). 4.16.7.2 compare match blocking by tcnt1 write all cpu writes to the tcnt1 register will blo ck any compare match that occurs in the next timer clock cycle, even when the timer is stopped . this feature allows ocr1x to be initialized to the same value as tcnt1 without triggering an interrupt when the timer/counter clock is enabled. 4.16.7.3 using the output compare unit since writing tcnt1 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing tcnt1 when using any of the output compare channels, independent of whether the timer/counter is running or not. if the value written to tcnt1 equals the ocr1x value, the compare match will be missed, resulting in incorrect waveform generation. do not write the tcnt1 equal to top in pwm modes with variable top values. the compare match for th e top will be ignored a nd the counter will con- tinue to 0xffff. similarly, do not write the tcnt1 value equal to bottom when the counter is downcounting. the setup of the oc1x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc1x value is to use the force output com- pare (1x) strobe bits in normal mode. the oc1x register keeps its value even when changing between waveform generation modes.
105 9137e?rke?12/10 atmel ATA5771/73/74 be aware that the com1x1:0 bits are not double buffered together with the compare value. changing the com1x1:0 bits will take effect immediately. 4.16.8 compare match output unit the compare output mode (com1x1:0) bits have two functions. the waveform generator uses the com1x1:0 bits for defining the output compare (oc1x) state at the next compare match. secondly the com1x1:0 bits control the oc1x pin output source. figure 4-41 shows a simplified schematic of the logic affected by t he com1x1:0 bit setting. the i/o registers, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that ar e affected by the com1x1:0 bi ts are shown. when referring to the oc1x state, the reference is for the inte rnal oc1x register, not the oc1x pin. if a sys- tem reset occur, the oc1x register is reset to ?0?. figure 4-41. compare match output unit, schematic the general i/o port function is overridden by the output compare (oc1x) from the waveform generator if either of the com1x1:0 bits are set. however, the oc1x pin direction (input or output) is still co ntrolled by the data direction register (ddr) for the port pin. the data direc- tion register bit for the oc1x pin (ddr_oc1x) must be set as output before the oc1x value is visible on the pin. the port override function is generally independent of the waveform gener- ation mode, but there are some exceptions. see table 4-39 on page 116 , table 4-40 on page 116 and table 4-41 on page 117 for details. the design of the output compare pin logic allows initialization of the oc1x state before the output is enabled. note that some com1x1:0 bit settings are reserved for certain modes of operation. see section 4.11.5 ?register description? on page 51 the com1x1:0 bits have no effect on the input capture unit. port ddr dq dq ocnx pin ocnx dq waveform generator comnx1 comnx0 0 1 data b u s focnx clk i/o
106 9137e?rke?12/10 atmel ATA5771/73/74 4.16.8.1 compare output mode and waveform generation the waveform generator uses the com1x1:0 bits differently in normal, ctc, and pwm modes. for all modes, setting the com1x1:0 = 0 tells the waveform generator that no action on the oc1x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 4-39 on page 116 . for fast pwm mode refer to table 4-40 on page 116 , and for phase correct and phase and frequency correct pwm refer to table 4-41 on page 117 . a change of the com1x1:0 bits state will have effe ct at the first compare match after the bits are written. for non-pwm modes, the action can be forced to have immediate effect by using the 1x strobe bits. 4.16.9 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm13:0) and compare output mode (com1x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com1x1:0 bits control whether the pwm output generated should be inverted or not (inverted or non-inverted pwm). for non-pwm modes the com1x1:0 bits control whether the output should be set, cleared or tog- gle at a compare match ( section 4.15.6 ?compare match output unit? on page 80 ) for detailed timing information refer to section 4.15.8 ?timer/counter timing diagrams? on page 86 . 4.16.9.1 normal mode the simplest mode of operation is the normal mode (wgm13:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 16-bit valu e (max = 0xffff) and then restarts from the bottom (0x0000). in normal operation the timer/counter overflow flag (tov1) will be set in the same timer clock cycle as the tcnt1 become s zero. the tov1 flag in this case behaves like a 17th bit, except that it is only set, not cleared. however, combined with the timer over- flow interrupt that automatically clears the tov1 flag, the timer resolution can be increased by software. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the input capture unit is easy to use in normal mode. however, observe that the maximum interval between the external events must not exceed the resolution of the counter. if the inter- val between events are too long, the timer overflow interrupt or the prescaler must be used to extend the resolution for the capture unit. the output compare units can be used to generate interrupts at some given time. using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the cpu time. 4.16.9.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm13:0 = 4 or 12), the ocr1a or icr1 register are used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the counter value (tcnt1) matches either the ocr1a (wgm13:0 = 4) or the icr1 (wgm13:0 = 12). the ocr1a or icr1 define the top value for the counter, hence also its res- olution. this mode allows greater control of the compare match output frequency. it also simplifies the operation of counting external events.
107 9137e?rke?12/10 atmel ATA5771/73/74 the timing diagram for the ctc mode is shown in figure 4-42 . the counter value (tcnt1) increases until a compare match occurs with either ocr1a or icr1, and then counter (tcnt1) is cleared. figure 4-42. ctc mode, timing diagram an interrupt can be generated at each time the counter value reaches the top value by either using the ocf1a or icf1 flag according to the register used to define the top value. if the interrupt is enabled, the interrupt handler routine can be used for updating the top value. however, changing the top to a value close to bottom when the counter is running with none or a low prescaler value must be done with care since the ctc mode does not have the double buffering feature. if the new value written to ocr1a or icr1 is lower than the current value of tcnt1, the counter will miss the compar e match. the counter will then have to count to its maximum value (0xffff) and wrap around starting at 0x0000 before the compare match can occur. in many cases this feature is not desirable. an alternative will then be to use the fast pwm mode using ocr1a for defining top (wgm13:0 = 15) since the ocr1a then will be double buffered. for generating a waveform output in ctc mode, the oc1a output can be set to toggle its log- ical level on each compare match by setting the compare output mode bits to toggle mode (com1a1:0 = 1). the oc1a value will not be visi ble on the port pin unless the data direction for the pin is set to output (ddr_oc1a = 1) . the waveform genera ted will have a maximum frequency of 1 a = f clk_i/o /2 when ocr1a is set to zero (0x0000). the waveform frequency is defined by the following equation: the n variable represents the prescaler factor (1, 8, 64, 256, or 1024). as for the normal mode of operation, the tov1 flag is set in the sa me timer clock cycle that the counter counts from max to 0x0000. tcntn ocna (toggle) ocna interrupt flag set or icfn interrupt flag set (interrupt on top) 1 4 period 2 3 (comna1:0 = 1) f ocna f clk_i/o 2 n 1 ocrna + () ?? ------------------------------------------------------- =
108 9137e?rke?12/10 atmel ATA5771/73/74 4.16.9.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm13:0 = 5, 6, 7, 14, or 15) provides a high frequency pwm waveform generation option. the fast pwm differs from the other pwm options by its single-slope operation. the counter counts from bottom to top then restarts from bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x, and set at bottom. in inverting compare output mode output is set on compare match and cleared at bottom. due to the single-slope operation, the operating frequency of the fast pwm mode can be twice as high as the phase correct and phase and frequency correct pwm modes that use dual-slope opera- tion. this high frequency makes the fast pwm mode well suited for power regulation, rectification, and dac applications. high fre quency allows physically small sized external components (coils, capacitors), hence reduces total system cost. the pwm resolution for fast pwm can be fixed to 8-, 9-, or 10-bit, or defined by either icr1 or ocr1a. the minimum resolution allowed is 2- bit (icr1 or ocr1a set to 0x0003), and the maximum resolution is 16-bit (i cr1 or ocr1a set to max). the pwm resolution in bits can be calculated by using the following equation: in fast pwm mode the counter is incremented until the counter value matches either one of the fixed values 0x00ff, 0x01ff, or 0x03ff (wgm13:0 = 5, 6, or 7), the value in icr1 (wgm13:0 = 14), or the value in ocr1a (wgm13:0 = 15). the counter is then cleared at the following timer clock cycle. the timing diagram for the fast pwm mode is shown in figure 4-43 . the figure shows fast pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for illustra ting the single-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be se t when a compare match occurs. figure 4-43. fast pwm mode, timing diagram the timer/counter overflow flag (tov1) is se t each time the counter reaches top. in addi- tion the oc1a or icf1 flag is set at the sa me timer clock cycle as tov1 is set when either ocr1a or icr1 is used for de fining the top value. if one of the interrupts are enabled, the interrupt handler routine can be used for updating the top and compare values. r fpwm top 1 + () log 2 () log ---------------------------------- - = tcntn ocrnx/top update and tovn interrupt flag set and ocna interrupt flag set or icfn interrupt flag set (interrupt on top) 1 7 period 2 3 4 5 6 8 ocnx ocnx (comnx1:0 = 2) (comnx1:0 = 3)
109 9137e?rke?12/10 atmel ATA5771/73/74 when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will nev er occur between the tcnt1 and the ocr1x. note that when using fixed top values the unused bits are masked to zero when any of the ocr1x registers are written. the procedure for updating icr1 differs from updating ocr1a when used for defining the top value. the icr1 register is not double buffered. this means that if icr1 is changed to a low value when the counter is running with none or a low prescaler value, there is a risk that the new icr1 value written is lower than the current value of tcnt1. the result will then be that the counter will miss the compare match at the top value. the counter will then have to count to the max value (0xffff) and wrap around starting at 0x0000 before the compare match can occur. the ocr1a register however, is double buffered. this feature allows the ocr1a i/o location to be written anytime. when the ocr1a i/o location is written the value written will be put into the ocr1a buffer re gister. the ocr1a compar e register will then be updated with the value in the buffer register at the next timer clock cycle the tcnt1 matches top. the update is done at the same timer clock cycle as the tcnt1 is cleared and the tov1 flag is set. using the icr1 register for defining top work s well when using fixed top values. by using icr1, the ocr1a register is free to be used for generating a pwm output on oc1a. how- ever, if the base pwm frequency is actively changed (by changing the top value), using the ocr1a as top is clearly a better choice due to its double buffer feature. in fast pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm out- put can be generated by setting the com1x1:0 to three (see table 4-40 on page 116 ). the actual oc1x value will only be visible on the port pin if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1, and clearing (or setting) the oc1x register at the timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represents special cases when generating a pwm waveform output in the fast pwm mode. if the ocr1x is set equal to bottom (0x0000) the output will be a narrow spike for each top+1 timer clock cycle. setting the ocr1x equal to top will result in a constant high or low output (d epending on the polar ity of the output set by the com1x1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by setting oc1a to toggle its logical level on each compare match (com1a1:0 = 1). the wave- form generated will have a maximum frequency of 1 a = f clk_i/o /2 when ocr1a is set to zero (0x0000). this feature is similar to the oc1a toggle in ctc mode, except the double buffer feature of the output compare unit is enabled in the fast pwm mode. f ocnxpwm f clk_i/o n 1 top + () ? ------------------------------------- =
110 9137e?rke?12/10 atmel ATA5771/73/74 4.16.9.4 phase correct pwm mode the phase correct pulse width modulation or phase correct pwm mode (wgm13:0 = 1, 2, 3, 10, or 11) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is, like the phase and frequency correct pwm mode, based on a dual-slope operation. the counter counts repeatedly from bottom (0x0000) to top and then from top to bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x while upcounting, and set on the compare match while downcounting. in inverting output compare mode, the opera- tion is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the symmetric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. the pwm resolution for the phase correct pwm mode can be fixed to 8-, 9-, or 10-bit, or defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and the maximum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolution in bits can be calculated by using the following equation: in phase correct pwm mode the counter is incremented until the counter value matches either one of the fixed values 0x00ff, 0x01ff, or 0x03ff (wgm13:0 = 1, 2, or 3), the value in icr1 (wgm13:0 = 10), or the value in ocr1a (wgm13:0 = 11). the counter has then reached the top and changes the count direction. the tcnt1 value will be equal to top for one timer clock cycle. the timing diagram for th e phase correct pwm mode is shown on figure 4-44 . the figure shows phase correct pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be se t when a compare match occurs. figure 4-44. phase correct pwm mode, timing diagram r pcpwm top 1 + () log 2 () log ---------------------------------- - = ocrnx/top update and ocna interrupt flag set or icfn interrupt flag set (interrupt on top) 1 2 3 4 tovn interrupt flag set (interrupt on bottom) tcntn period ocnx ocnx (comnx1:0 = 2) (comnx1:0 = 3)
111 9137e?rke?12/10 atmel ATA5771/73/74 the timer/counter overflow flag (tov1) is set each time the counter reaches bottom. when either ocr1a or icr1 is used for defining the top value, the oc1a or icf1 flag is set accordingly at the same timer clock cycle as the ocr1x registers are updated with the dou- ble buffer value (at top). the interrupt flags can be used to generate an interrupt each time the counter reaches the top or bottom value. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will nev er occur between the tcnt1 and the ocr1x. note that when using fixed top values, the unus ed bits are masked to zero when any of the ocr1x registers are written. as the third period shown in figure 4-44 on page 110 illustrates, changing the top actively while the timer/count er is running in the phase correct mode can result in an unsymmetrical output. the reason for this can be found in the time of update of the ocr1x register. since the ocr1x update occurs at top, the pwm period starts and ends at top. this implies that the length of the falling slope is determined by the previous top value, while the length of the rising slope is determined by the new top value. when these two val- ues differ the two slopes of the period will di ffer in length. the difference in length gives the unsymmetrical result on the output. it is recommended to use the phase and frequency correct mode instead of the phase correct mode when changing the top value while the ti mer/counter is running. when using a static top value there are practically no differences between the two modes of operation. in phase correct pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table 4-41 on page 117 ). the actual oc1x value will on ly be visible on the port pi n if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1 when the counter increments, and clearing (or setting) the oc1x register at compare match between ocr1x and tcnt1 when the counter decrements. the pwm frequency for the output when using phase correct pwm can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr1x is set equal to bottom the output will be continuously low and if set equal to top the ou tput will be continuously high for non-inverted pwm mode. for in verted pwm the output will have the opposite logic values. f ocnxpcpwm f clk_i/o 2 ntop ?? --------------------------------- =
112 9137e?rke?12/10 atmel ATA5771/73/74 4.16.9.5 phase and frequency correct pwm mode the phase and frequency correct pulse width modulation, or phase and frequency correct pwm mode (wgm13:0 = 8 or 9) provides a high resolution phase and frequency correct pwm waveform generation option. the phase and frequency correct pwm mode is, like the phase correct pwm mode, based on a dual-slope operation. the counter counts repeatedly from bottom (0x0000) to top and then from top to bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x while upcounting, and set on the compare match while downcounting. in inverting compare output mode, the operation is inverted. the dual-slope operation gives a lower max- imum operation frequency compared to the single-slope operation. however, due to the symmetric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. the main difference between the phase corr ect, and the phase and frequency correct pwm mode is the time the ocr1x register is updated by the ocr1x buffer register, (see figure 4-44 on page 110 and figure 4-45 on page 113 ). the pwm resolution for the phase and frequency correct pwm mode can be defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and the maximum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolution in bits can be calculated using the following equation: in phase and frequency correct pwm mode the counter is incremented until the counter value matches either the value in icr1 (wgm13:0 = 8), or the value in ocr1a (wgm13:0 = 9). the counter has then re ached the top and change s the count direction. the tcnt1 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct and fre- quency correct pwm mode is shown on figure 4-45 on page 113 . the figure shows phase and frequency correct pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a hist ogram for illustrating t he dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be set when a compare match occurs. r pfcpwm top 1 + () log 2 () log ---------------------------------- - =
113 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-45. phase and frequency correct pwm mode, timing diagram the timer/counter overflow flag (tov1) is set at the same timer clock cycle as the ocr1x registers are updated with the double buffer value (at bottom). when either ocr1a or icr1 is used for defining the top value, the oc1a or icf1 flag set when tcnt1 has reached top. the interrupt flags can then be used to generate an interrupt each time the counter reaches the top or bottom value. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will neve r occur between the tcnt1 and the ocr1x. as figure 4-45 shows the output generated is, in contrast to the phase correct mode, symmet- rical in all periods. since the ocr1x registers are updated at bottom, the length of the rising and the falling slopes will always be equal. this gives symme trical output pulses and is therefore frequency correct. using the icr1 register for defining top work s well when using fixed top values. by using icr1, the ocr1a register is free to be used for generating a pwm output on oc1a. how- ever, if the base pwm frequency is actively changed by changing the top value, using the ocr1a as top is clearly a better choice due to its double buffer feature. in phase and frequency correct pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table 4-41 on page 117 ). the actual oc1x value will only be visible on the port pin if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1 when the counter increments, and clearing (or setting) the oc1x register at compare match between ocr1x and tcnt1 when the counter decrements. the pwm frequency for the out- put when using phase and frequency correct pw m can be calculated by the following equation: ocrnx/top updateand tovn interrupt flag set (interrupt on bottom) ocna interrupt flag set or icfn interrupt flag set (interrupt on top) 1 2 3 4 tcntn period ocnx ocnx (comnx1:0 = 2) (comnx1:0 = 3) f ocnxpfcpwm f clk_i/o 2 ntop ?? --------------------------------- =
114 9137e?rke?12/10 atmel ATA5771/73/74 the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represents special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr1x is set equal to bot- tom the output will be cont inuously low and if set equal to to p the output will be set to high for non-inverted pwm mode. for inverted pwm the output will have the opposite logic values. 4.16.10 timer/counter timing diagrams the timer/counter is a synchronous design and the timer clock (clk t1 ) is therefore shown as a clock enable signal in the following figures. the figures include information on when interrupt flags are set, and when the ocr1x register is updated with the ocr1x buffer value (only for modes utilizing double buffering). figure 4-46 shows a timing diagram for the setting of ocf1x. figure 4-46. timer/counter timing diagram, setting of ocf1x, no prescaling figure 4-47 shows the same timing data, but with the prescaler enabled. figure 4-47. timer/counter timing diagram, setting of ocf1x, with prescaler (f clk_i/o /8) clk tn (clk i/o /1) ocfnx clk i/o ocrnx tcntn ocrnx value ocrnx - 1 ocrnx ocrnx + 1 ocrnx + 2 ocfnx ocrnx tcntn ocrnx value ocrnx - 1 ocrnx ocrnx + 1 ocrnx + 2 clk i/o clk tn (clk i/o /8)
115 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-48 shows the count sequence close to to p in various modes. when using phase and frequency correct pwm mode the ocr1x register is updated at bottom. the timing diagrams will be the same, but top should be replaced by bottom, top-1 by bottom+1 and so on. the same renaming applies for modes that set the tov1 flag at bottom. figure 4-48. timer/counter timing diagram, no prescaling figure 4-49 shows the same timing data, but with the prescaler enabled. figure 4-49. timer/counter timing dia gram, with prescaler (f clk_i/o /8) tovn (fpwm) and icfn (if used as top) ocrnx (update at top) tcntn (ctc and fpwm) tcntn (pc and pfc pwm) top - 1 top top - 1 top - 2 old ocrnx value new ocrnx value top - 1 top bottom bottom + 1 clk tn (clk i/o /1) clk i/o tovn (fpwm) and icf n (if used as top) ocrnx (update at top) tcntn (ctc and fpwm) tcntn (pc and pfc pwm) top - 1 top top - 1 top - 2 old ocrnx value new ocrnx value top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o /8)
116 9137e?rke?12/10 atmel ATA5771/73/74 4.16.11 register description 4.16.11.1 tccr1a ? timer/counter1 control register a ? bit 7:6 ? com1a1:0: compare output mode for channel a ? bit 5:4 ? com1b1:0: compare output mode for channel b the com1a1:0 and com1b1:0 control the output compare pins (oc1a and oc1b respec- tively) behavior. if one or both of the com1a1:0 bits are written to one, the oc1a output overrides the normal port functionality of the i /o pin it is connected to. if one or both of the com1b1:0 bit are written to one, the oc1b output overrides the normal port functionality of the i/o pin it is connected to. however, note that the data direction register (ddr) bit corre- sponding to the oc1a or oc1b pin must be set in order to enable the output driver. when the oc1a or oc1b is connected to the pi n, the function of the com1x1:0 bits is depen- dent of the wgm13:0 bits setting. table 4-39 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to a normal or a ctc mode (non-pwm). table 4-40 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to the fast pwm mode. note: 1. a special case occurs when ocr1a/oc r1b equals top and com1a1/com1b1 is set. in this case the compare match is ignored, but the set or clear is done at bottom. section 4.15.7.3 ?fast pwm mode? on page 83 for more details. bit 7 6 5 4 3210 0x2f (0x4f) com1a1 com1a0 com1b1 com1b0 ? ? wgm11 wgm10 tccr1a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 table 4-39. compare output mode, non-pwm com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 0 1 toggle oc1a/oc1b on compare match. 10 clear oc1a/oc1b on compare match (set output to low level). 11 set oc1a/oc1b on compare match (set output to high level). table 4-40. compare output mode, fast pwm (1) com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 01 wgm13=0: normal port operation, oc1a/oc1b disconnected. wgm13=1: toggle oc1a on compare match, oc1b reserved. 10 clear oc1a/oc1b on compare match, set oc1a/oc1b at bottom (non-inverting mode) 11 set oc1a/oc1b on compare match, clear oc1a/oc1b at bottom (inverting mode)
117 9137e?rke?12/10 atmel ATA5771/73/74 table 4-41 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to the phase correct or the phase and frequency correct, pwm mode. note: 1. a special case occurs when ocr1a/ ocr1b equals top and com1a1/com1b1 is set. section 4.16.9.4 ?phase correct pwm mode? on page 110 for more details. ? bit 1:0 ? wgm11:0: waveform generation mode combined with the wgm13:2 bits found in the tccr1b register, these bits control the count- ing sequence of the counter, the source for maximum (top) counter value, and what type of waveform generation to be used, see table 4-42 on page 118 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and three types of pulse width modulation (pwm) modes. ( section 4.16.9 ?modes of operation? on page 106 ). table 4-41. compare output mode, phase correct and phase and frequency correct pwm (1) com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 01 wgm13=0: normal port operation, oc1a/oc1b disconnected. wgm13=1: toggle oc1a on compare match, oc1b reserved. 10 clear oc1a/oc1b on compare match when up-counting. set oc1a/oc1b on compare match when downcounting. 11 set oc1a/oc1b on compare match when up-counting. clear oc1a/oc1b on compare match when downcounting.
118 9137e?rke?12/10 atmel ATA5771/73/74 note: 1. the ctc1 and pwm11:0 bit definition names are obsolete. use the wgm12:0 definitions. however, the functionality and location of these bits are compatible with previous versions of the timer. 4.16.11.2 tccr1b ? timer/counter1 control register b ? bit 7 ? icnc1: input capture noise canceler setting this bit (to one) activates the input capture noise canceler. when the noise canceler is activated, the input from the input capture pi n (icp1) is filtered. the filter function requires four successive equal valued samples of the icp1 pin for changing its output. the input cap- ture is therefore dela yed by four osc illator cycles when the noise canceler is enabled. ? bit 6 ? ices1: input capture edge select this bit selects which edge on the input capture pin (icp1) that is used to trigger a capture event. when the ices1 bit is written to zero, a falling (negative) edge is used as trigger, and when the ices1 bit is written to one, a risi ng (positive) edge w ill trigger the capture. when a capture is triggered according to the ices1 setting, the counter value is copied into the input capture regist er (icr1). the event will also se t the input capture flag (icf1), and this can be used to cause an input capture interrupt, if this interrupt is enabled. table 4-42. waveform generation mode bit description (1) mode wgm13 wgm12 (ctc1) wgm11 (pwm11) wgm10 (pwm10) timer/counter mode of operation top update of ocr1 x at tov1 flag set on 0 0 0 0 0 normal 0xffff immediate max 1 0 0 0 1 pwm, phase correct, 8-bit 0x00ff top bottom 2 0 0 1 0 pwm, phase correct, 9-bit 0x01ff top bottom 3 0 0 1 1 pwm, phase correct, 10-bit 0x03ff top bottom 4 0 1 0 0 ctc ocr1a immediate max 5 0 1 0 1 fast pwm, 8-bit 0x00ff bottom top 6 0 1 1 0 fast pwm, 9-bit 0x01ff bottom top 7 0 1 1 1 fast pwm, 10-bit 0x03ff bottom top 81000 pwm, phase and frequency correct icr1 bottom bottom 91001 pwm, phase and frequency correct ocr1a bottom bottom 10 1 0 1 0 pwm, phase correct icr1 top bottom 11 1 0 1 1 pwm, phase correct ocr1a top bottom 12 1 1 0 0 ctc icr1 immediate max 13 1 1 0 1 (reserved) ? ? ? 141110fast pwm icr1bottomtop 151111fast pwm ocr1abottomtop bit 7 6 5 4 3 2 1 0 0x2e (0x4e) icnc1 ices1 ? wgm13 wgm12 cs12 cs11 cs10 tccr1b read/write r/w r/w r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
119 9137e?rke?12/10 atmel ATA5771/73/74 when the icr1 is used as top value (see description of the wgm13:0 bits located in the tccr1a and the tccr1b register), the icp1 is disconnected and consequently the input capture function is disabled. ? bit 5 ? reserved bit this bit is reserved for future use. for ensuri ng compatibility wit h future devices, this bit must be written to zero wh en tccr1b is written. ? bit 4:3 ? wgm13:2: waveform generation mode see tccr1a register description. ? bit 2:0 ? cs12:0: clock select the three clock select bits select the clock source to be used by the timer/counter, see fig- ure 4-33 on page 86 and figure 4-34 on page 87 . if external pin modes are used for the timer/c ounter1, transitions on the t1 pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 4.16.11.3 tccr1c ? timer/counter1 control register c ? bit 7 ? foc1a: force output compare for channel a ? bit 6 ? foc1b: force output compare for channel b the foc1a/foc1b bits are only active when the wgm13:0 bits specifies a non-pwm mode. however, for ensuring compatibilit y with future devices, these bits must be set to zero when tccr1a is written when operating in a pwm mode. when writing a logical one to the foc1a/foc1b bit, an immediate compare match is forced on the waveform generation unit. the oc1a/oc1b output is changed according to its com1x1:0 bits setting. note that the foc1a/foc1b bits are implemented as strobes. therefore it is the value present in the com1x1:0 bits that determine the effect of the forced compare. table 4-43. clock select bit description cs12 cs11 cs10 description 0 0 0 no clock source (timer/counter stopped). 001clk i/o /1 (no prescaling) 010clk i/o /8 (from prescaler) 011clk i/o /64 (from prescaler) 100clk i/o /256 (from prescaler) 101clk i/o /1024 (from prescaler) 1 1 0 external clock source on t1 pin. clock on falling edge. 1 1 1 external clock source on t1 pin. clock on rising edge. bit 7654 3210 0x22 (0x42) foc1a foc1b ? ? ? ? ? ? tccr1c read/write w w r r r r r r initial value 0 0 0 0 0 0 0 0
120 9137e?rke?12/10 atmel ATA5771/73/74 a foc1a/foc1b strobe will not gener ate any interrupt nor will it cl ear the timer in clear timer on compare match (ctc) mode using ocr1a as top. the foc1a/foc1b bits are always read as zero. ? bit 5..0 ? reserved bit this bit is reserved for future use. for ensuri ng compatibility wit h future devices, this bit must be written to zero when the register is written. 4.16.11.4 tcnt1h and tcnt1l ? timer/counter1 the two timer/counter i/o locations (tcnt1h and tcnt1l, combined tcnt1) give direct access, both for read and for write operations, to the timer/counter unit 16-bit counter. to ensure that both the high and low bytes are read and written simultaneously when the cpu accesses these registers, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. see section 4.16.3 ?accessing 16-bit registers? on page 97 . modifying the counter (tcnt1) while the counter is running introduces a risk of missing a compare match between tcnt1 and one of the ocr1x registers. writing to the tcnt1 register blocks (remov es) the compare match on the following timer clock for all compare units. 4.16.11.5 ocr1ah and ocr1al ? output compare register 1 a 4.16.11.6 ocr1bh and ocr1bl ? output compare register 1 b the output compare registers contain a 16-bit value that is continuously compared with the counter value (tcnt1). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc1x pin. the output compare registers are 16-bit in size. to ensure that both the high and low bytes are written simultaneously when the cpu writes to these registers, the access is performed using an 8-bit temporary high byte register (tem p). this temporary register is shared by all the other 16-bit registers. see section 4.16.3 ?accessing 16-bit registers? on page 97 . bit 76543210 0x2d (0x4d) tcnt1[15:8] tcnt1h 0x2c (0x4c) tcnt1[7:0] tcnt1l read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x2b (0x4b) ocr1a[15:8] ocr1ah 0x2a (0x4a) ocr1a[7:0] ocr1al read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x29 (0x49) ocr1b[15:8] ocr1bh 0x28 (0x48) ocr1b[7:0] ocr1bl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
121 9137e?rke?12/10 atmel ATA5771/73/74 4.16.11.7 icr1h and icr1l ? input capture register 1 the input capture is updated with the counter (tcnt1) value each time an event occurs on the icp1 pin (or optionally on the analog comparator output for timer/counter1). the input capture can be used for defining the counter top value. the input capture register is 16-bit in size. to ensure that both the high and low bytes are read simultaneously when the cpu accesses these registers, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. section 4.16.3 ?accessing 16-bit registers? on page 97 . 4.16.11.8 timsk1 ? timer/counter interrupt mask register 1 ? bit 7,6,4,3 ? reserved bit this bit is reserved for future use. for ensuri ng compatibility wit h future devices, this bit must be written to zero when the register is written. ? bit 5 ? icie1: timer/counter1, input capture interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/countern input capture interrupt is enabled. the corresponding interrupt vector (see ?interrupts? on page 66.) is executed when the icf1 flag, located in tifr1, is set. ? bit 2? ocie1b: timer/counter1, output compare b match interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 output compare b match interrupt is enabled. the correspond- ing interrupt vector (see section 4.12 ?interrupts? on page 55 ) is executed when the ocf1b flag, located in tifr1, is set. ? bit 1? ocie1a: timer/counter1, output compare a match interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 output compare a match interrupt is enabled. the correspond- ing interrupt vector (see section 4.12 ?interrupts? on page 55 ) is executed when the ocf1a flag, located in tifr1, is set. ? bit 0 ? toie1: timer/counter1, overflow interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 overflow interrupt is enabled. the corresponding interrupt vec- tor (see section 4.12 ?interrupts? on page 55 ) is executed when the tov1 flag, located in tifr1, is set. bit 76543210 0x25 (0x45) icr1[15:8] icr1h 0x24 (0x44) icr1[7:0] icr1l read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 0x0c (0x2c) ? ? icie1 ? ? ocie1b ocie1a toie1 timsk1 read/write r r r/w r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
122 9137e?rke?12/10 atmel ATA5771/73/74 4.16.11.9 tifr1 ? timer/counter interrupt flag register 1 ? bit 7,6,4,3 ? reserved bit this bit is reserved for future use. for ensuri ng compatibility wit h future devices, this bit must be written to zero when the register is written. ? bit 5? icf1: timer/counter1, input capture flag this flag is set when a capture event occurs on the icp1 pin. when the input capture register (icr1) is set by the wgm13:0 to be used as the top value, the icf1 flag is set when the counter reaches the top value. icf1 is automatically cleared when the input capture interrupt vector is executed. alterna- tively, icf1 can be cleared by writing a logic one to its bit location. ? bit 2? ocf1b: timer/counter1, output compare b match flag this flag is set in the timer clock cycle afte r the counter (tcnt1) value matches the output compare register b (ocr1b). note that a forced output compare (1 b) strobe will not set the ocf1b flag. ocf1b is automatically cleared when the output compare match b interrupt vector is exe- cuted. alternatively, ocf1b can be cleared by writing a logic one to its bit location. ? bit 1? ocf1a: timer/counter1, output compare a match flag this flag is set in the timer clock cycle afte r the counter (tcnt1) value matches the output compare register a (ocr1a). note that a forced output compare (1 a) strobe will not set the ocf1a flag. ocf1a is automatically cleared when the output compare match a interrupt vector is exe- cuted. alternatively, ocf1a can be cleared by writing a logic one to its bit location. ? bit 0? tov1: timer/counter1, overflow flag the setting of this flag is dependent of the wgm13:0 bits setting. in normal and ctc modes, the tov1 flag is set when the timer overflows. see table 4-42 on page 118 for the tov1 flag behavior when using another wgm13:0 bit setting. tov1 is automatically cleared when the timer/co unter1 overflow interrupt vector is exe- cuted. alternatively, tov1 can be cleared by writing a logic one to its bit location. bit 765432 1 0 0x0b (0x2b) ? ? icif1 ? ? ocf1b ocf1a tov1 tifr1 read/write r r r/w r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
123 9137e?rke?12/10 atmel ATA5771/73/74 4.17 timer/counter prescaler timer/counter 0, and 1 share the same presca ler module, but the timer/counters can have different prescaler settings. the description below applies to all timer/counters. tn is used as a general name, n = 0, 1. the timer/counter can be clocked directly by the system clock (by setting the csn2:0 = 1). this provides the fastest operation, with a maximum timer/counter clock frequency equal to system clock frequency (f clk_i/o ). alternatively, one of four taps from the prescaler can be used as a clock source. the prescaled clock has a frequency of either f clk_i/o /8, f clk_i/o /64, f clk_i/o /256, or f clk_i/o /1024. 4.17.1 prescaler reset the prescaler is free running, i.e., operates in dependently of the clock select logic of the timer/countercounter, and it is shared by the timer/counter tn. since the prescaler is not affected by the timer/counter?s clock select, the state of the prescaler will have implications for situations where a prescaled clock is used. one example of prescaling artifacts occurs when the timer is enabled and clocked by the prescaler (6 > csn2:0 > 1). the number of sys- tem clock cycles from when the timer is enabled to the first count occurs can be from 1 to n+1 system clock cycles, where n equals the prescaler divisor (8, 64, 256, or 1024). it is possible to use the prescaler reset for synchronizing the timer/counter to program execution. 4.17.1.1 external clock source an external clock source applied to the tn pin can be used as timer/counter clock (clk tn ). the tn pin is sampled once every system clock cycle by the pin synchronization logic. the syn- chronized (sampled) signal is then passed through the edge detector. figure 4-50 shows a functional equivalent block diagram of the tn synchronization and edge detector logic. the registers are clocked at the positive edge of the internal system clock ( clk i/o ). the latch is transparent in the high period of the internal system clock. the edge detector generates one clk t 0 pulse for each positive (csn2:0 = 7) or negative (csn2:0 = 6) edge it detects. figure 4-50. t0 pin sampling the synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge has been applied to the tn pin to the counter is updated. enabling and disabling of the clock input must be done when tn has been stable for at least one system clock cycle, otherwise it is a ri sk that a false timer/counter clock pulse is generated. tn_sync (to clock select logic) edge detector synchronization dq dq le dq tn clk i/o
124 9137e?rke?12/10 atmel ATA5771/73/74 each half period of the external clock applied must be longer than one system clock cycle to ensure correct sampling. the external clock must be guaranteed to have less than half the system clock frequency (f extclk < f clk_i/o /2) given a 50/50% duty cycle. since the edge detector uses sampling, the maximum frequency of an exte rnal clock it can detect is half the sampling frequency (nyquist sampling theorem). however, due to variation of the system clock fre- quency and duty cycle caused by oscillator source (crystal , resonator, and capacitors) tolerances, it is recommended that maximum fr equency of an external clock source is less than f clk_i/o /2.5. an external clock source can not be prescaled. figure 4-51. prescaler for timer/counter0 note: 1. the synchronization logic on the input pins ( t0) is shown in figure 4-50 on page 123 . 4.17.2 register description 4.17.2.1 gtccr ? general timer/counter control register ? bit 7 ? tsm: timer/counter synchronization mode writing the tsm bit to one activates the timer/counter synchronization mode. in this mode, the value that is written to the psr10 bit is kept, hence keeping the prescaler reset signal asserted. this ensures that the timer/counter is halted and can be configured without the risk of advancing during configuration. when the tsm bit is written to zero, the psr10 bit is cleared by hardware, and the timer/counter start counting. ? bit 0 ? psr10: prescaler 0 reset timer/counter n when this bit is one, the timer/countern prescaler will be reset. this bit is normally cleared immediately by hardware, except if the tsm bit is set. psr10 clear clk t0 t0 clk i/o synchronization bit 7 6 5 4 3 2 1 0 0x23 (0x43) tsm ? ? ? ? ? ? psr10 gtccr read/write r/w r r r r r r r/w initial value 0 0 0 0 0 0 0 0
125 9137e?rke?12/10 atmel ATA5771/73/74 4.18 usi ? universal serial interface 4.18.1 features ? two-wire synchronous data tr ansfer (master or slave) ? three-wire synchronous data transfer (master or slave) ? data received interrupt ? wakeup from idle mode ? in two-wire mode: wake-up from all sleep modes, including power-down mode ? two-wire start condition detect or with interr upt capability 4.18.2 overview the universal serial interface (usi), provides the basic hardware resources needed for serial communication. combined with a minimum of c ontrol software, the usi allows significantly higher transfer rates and uses less code space than solutions based on software only. inter- rupts are included to minimize the processor load. a simplified block diagram of the usi is shown in figure 4-52 . for the actual placement of i/o pins. cpu accessible i/o registers, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit locations are listed in the section 4.9.10 ?register descrip- tion? on page 39 . figure 4-52. universal serial interface, block diagram the 8-bit shift register is directly accessi ble via the data bus and contains the incoming and outgoing data. the register has no buffering so the data must be read as quickly as possible to ensure that no data is lost. the most significant bit is connected to one of two output pins depending of the wire mode configuration. a transparent latch is inserted between the serial register output and output pin, which delays the change of data output to the opposite clock edge of the data input sampling. the serial input is always sampled from the data input (di) pin independent of the configuration. data bus usipf usitc usiclk usics0 usics1 usioif usioie usidc usisif usiwm0 usiwm1 usisie bit7 two-wire clock control unit do (output only) di/sda (input/open drain) usck/scl (input/open drain) 4-bit counter usidr usisr dq le usicr clock hold tim0 comp bit0 [1] 3 0 1 2 3 0 1 2 0 1 2
126 9137e?rke?12/10 atmel ATA5771/73/74 the 4-bit counter can be both read and written via the data bus, and can generate an overflow interrupt. both the serial register and the counter are clocked simultaneously by the same clock source. this allows the counter to coun t the number of bits received or transmitted and generate an interrupt when the transfer is comp lete. note that when an external clock source is selected the counter counts both clock edges. in this case the counter counts the number of edges, and not the number of bits. the clock can be selected from three different sources: the usck pin, timer/counter0 compare match or from software. the two-wire clock control unit can generate an interrupt when a start condition is detected on the two-wire bus. it can also generate wait st ates by holding the clock pin low after a start condition is detected, or after the counter overflows. 4.18.3 functional descriptions 4.18.3.1 three-wire mode the usi three-wire mode is compliant to the serial peripheral interface (spi) mode 0 and 1, but does not have the slave select (ss) pin functionality. however, this feature can be imple- mented in software if necessary. pin names used by this mode are: di, do, and usck. figure 4-53. three-wire mode operat ion, simplified diagram figure 4-53 shows two usi units operating in three-wire mode, one as master and one as slave. the two shift registers are interconnected in such way that after eight usck clocks, the data in each register are interchanged. the same clock also increments the usi?s 4-bit counter. the counter overflow (interrupt) flag, or usioif, can therefore be used to determine when a transfer is completed. the clock is generated by the master device software by tog- gling the usck pin via the port register or by writing a one to the usitc bit in usicr. slave master bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 do di usck bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 do di usck portxn
127 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-54. three-wire mode, timing diagram the three-wire mode timing is shown in figure 4-54 . at the top of the figure is a usck cycle reference. one bit is shifted into the usi shift register (usidr) for each of these cycles. the usck timing is shown for both external clock mo des. in external clock mode 0 (usics0 = 0), di is sampled at positive edges, and do is ch anged (data register is shifted by one) at nega- tive edges. external clock mode 1 (usics0 = 1) uses the opposite edges versus mode 0, i.e., samples data at negative and changes the output at positive edges. the usi clock modes cor- responds to the spi data mode 0 and 1. referring to the timing diagram ( figure 4-54 ), a bus transfer involves the following steps: 1. the slave device and master device sets up its data output and, depending on the pro- tocol used, enables its output driver (mark a and b). the output is set up by writing the data to be transmitted to the serial data register. enabling of the output is done by setting the corresponding bit in the port data direction register. note that point a and b does not have any specific order, but both must be at least one half usck cycle before point c where the data is sampled. this must be done to ensure that the data setup requirement is satisfied. the 4-bit counter is reset to zero. 2. the master generates a clock pulse by software toggling the usck line twice (c and d). the bit value on the slave and master?s data input (di) pin is sampled by the usi on the first edge (c), and the data output is changed on the opposite edge (d). the 4-bit counter will count both edges. 3. step 2 is repeated eight times for a complete register (byte) transfer. 4. after eight clock pulses (i.e ., 16 clock edges) the counter w ill overflow and indicate that the transfer is completed. the data bytes transferred must now be processed before a new transfer can be init iated. the overflow interrupt will wake up the processor if it is set to idle mode. depending of the protocol used the slave device can now set its out- put to high impedance. msb msb 654321lsb 1 2 3 4 5 6 7 8 654321lsb usck usck do di d c b a e cycle ( reference )
128 9137e?rke?12/10 atmel ATA5771/73/74 4.18.3.2 spi master operation example the following code demonstrates how to use the usi module as a spi master: spitransfer: out usidr,r16 ldi r16,(1< 129 9137e?rke?12/10 atmel ATA5771/73/74 in r16,usidr ret 4.18.3.3 spi slave operation example the following code demonstrates how to use the usi module as a spi slave: init: ldi r16,(1< 130 9137e?rke?12/10 atmel ATA5771/73/74 4.18.3.4 two-wire mode the usi two-wire mode is compliant to the inter ic (twi) bus protocol, but without slew rate limiting on outputs and input noise filtering. pin names used by this mode are scl and sda. figure 4-55. two-wire mode operation, simplified diagram figure 4-55 shows two usi units operating in two-wire mode, one as master and one as slave. it is only the physical layer that is shown since the system operation is highly depen- dent of the communication scheme used. the main differences between the master and slave operation at this level, is the serial clock generation which is always done by the master, and only the slave uses the clock control unit. clock generation must be implemented in software, but the shift operation is done automatically by both devices. note that only clocking on nega- tive edge for shifting data is of practical use in this mode. the slave can insert wait states at start or end of transfer by forcing the scl clock low. this means that the master must always check if the scl line was actually released after it has generated a positive edge. since the clock also increments the counter, a counter overflow can be used to indicate that the transfer is completed. the clock is generated by the master by toggling the usck pin via the port register. the data direction is not given by the physical layer. a protocol, like the one used by the twi-bus, must be implemented to control the data flow. master slave bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sda scl bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 two-wire clock control unit hold scl portxn sda scl vcc
131 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-56. two-wire mode, typical timing diagram referring to the timing diagram ( figure 4-56 ), a bus transfer involves the following steps: 1. the a start condition is generated by the master by forcing the sda low line while the scl line is high (a). sda can be forced low either by writing a zero to bit 7 of the shift register, or by setting the corresponding bit in the port register to zero. note that the data direction register bit must be set to one for the output to be enabled. the slave device?s start detector logic ( figure 4-57 ) detects the start condition and sets the usisif flag. the flag can generate an interrupt if necessary. 2. in addition, the start detector will hold the scl line low after the master has forced an negative edge on this line (b). this allows the slave to wake up from sleep or complete its other tasks before setting up the shift register to receive the address. this is done by clearing the start condition flag and reset the counter. 3. the master set the first bit to be transferred and releases the scl line (c). the slave samples the data and shift it into the serial register at the positive edge of the scl clock. 4. after eight bits are transferred containing slave address and data direction (read or write), the slave counter overflows and the scl line is forced low (d). if the slave is not the one the master has addressed, it releases the scl line and waits for a new start condition. 5. if the slave is addressed it holds the sda line low during the acknowledgment cycle before holding the scl line low again (i.e., the counter register must be set to 14 before releasing scl at (d)). depending of the r/w bit the master or slave enables its output. if the bit is set, a master read operation is in progress (i.e., the slave drives the sda line) the slave can hold the scl line low after the acknowledge (e). 6. multiple bytes can now be transmitted, all in same direction, until a stop condition is given by the master (f). or a new start condition is given. if the slave is not able to receive more data it does not acknowledge the data byte it has last received. when the master does a read operation it must terminate the operation by force the acknowledge bit low after the last byte transmitted. figure 4-57. start condition detector, logic diagram p s address 1 - 7 8 9 r/w ack ack 1 - 8 9 data ack 1 - 8 9 data sda scl a b d e c f sda scl write( usisif) clock hold usisif dq clr dq clr
132 9137e?rke?12/10 atmel ATA5771/73/74 4.18.3.5 start co ndition detector the start condition detector is shown in figure 4-57 on page 131 . the sda line is delayed (in the range of 50 to 300ns) to ensure valid sampling of the scl line. the start condition detector is only enabled in two-wire mode. the start condition detector is working asynch ronously and can therefore wake up the proces- sor from the power-down sleep mode. however, the protocol used might have restrictions on the scl hold time. therefore, when using this feature in this case the oscillator start-up time set by the cksel fuses (see section 4.9.1 ?clock systems and their distribution? on page 32 ) must also be taken into the consideration. see the usisif bit description in section 4.18.5.3 ?usisr ? usi status register? on page 133 for further details. 4.18.3.6 clock speed considerations maximum frequency for scl and sck is f ck /4. this is also the maximum data transmit and receieve rate in both two- and three-wire mode. in two-wire slave mode the two-wire clock control unit will hold the scl low until the slav e is ready to receive more data. this may reduce the actual data rate in two-wire mode. 4.18.4 alternative usi usage when the usi unit is not used for serial communication, it can be set up to do alternative tasks due to its flexible design. 4.18.4.1 half-duplex asynchronous data transfer by utilizing the shift register in three-wire mode, it is possible to impl ement a more compact and higher performance uart than by software only. 4.18.4.2 4-bit counter the 4-bit counter can be used as a stand-alone counter with overflow interrupt. note that if the counter is clocked externally, both clock edges will generate an increment. 4.18.4.3 12-bit timer/counter combining the usi 4-bit counter and timer/counter0 allows them to be used as a 12-bit counter. 4.18.4.4 edge triggered external interrupt by setting the counter to maximum value (f) it ca n function as an additional external interrupt. the overflow flag and interrupt enable bit are then used for the external interrupt. this fea- ture is selected by the usics1 bit. 4.18.4.5 software interrupt the counter overflow interrupt can be used as a software interrupt triggered by a clock strobe.
133 9137e?rke?12/10 atmel ATA5771/73/74 4.18.5 register descriptions 4.18.5.1 usibr ? usi data buffer 4.18.5.2 usidr ? usi data register the usi uses no buffering of the serial regi ster, i.e., when accessing the data register (usidr) the serial register is accessed directly. if a serial clock occurs at the same cycle the register is written, the register will contain t he value written and no shift is performed. a (left) shift operation is performed depending of the usics1..0 bits setting. the shift operation can be controlled by an external clock edge, by a timer/counter0 compare match, or directly by software using the usiclk strobe bit. note that even when no wire mode is selected (usiwm1..0 = 0) both the external data i nput (di/sda) and the external clock input (usck/scl) can still be used by the shift register. the output pin in use, do or sda depending on the wire mode, is connected via the output latch to the most significant bit (bit 7) of the data register. the output latch is open (transpar- ent) during the first half of a se rial clock cycle when an external clock source is selected (usics1 = 1), and constantly open when an inter nal clock source is used (usics1 = 0). the output will be changed immediat ely when a new msb written as long as the latc h is open. the latch ensures that data input is sampled and data output is changed on opposite clock edges. note that the corresponding data direction register to the pin must be set to one for enabling data output from the shift register. 4.18.5.3 usisr ? usi status register the status register contains interrupt flags, line status flags and the counter value. ? bit 7 ? usisif: start condition interrupt flag when two-wire mode is selected, the usisif flag is set (to one) when a start condition is detected. when output disable mode or three-wire mode is selected and (usicsx = 0b11 & usiclk = 0) or (usics = 0b10 & usiclk = 0), any edge on the sck pin sets the flag. an interrupt will be generated when the flag is set while the usisie bit in usicr and the global interrupt enable flag are set. the flag will only be cleared by writing a logical one to the usisif bit. clearing this bit will release the st art detection hold of us cl in two-wire mode. a start condition interr upt will wakeup the processor from all sleep modes. bit 7 6 5 4 3 2 1 0 0x10 (0x30) msb lsb usibr read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 0x0f (0x2f) msb lsb usidr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543 210 0x0e (0x2e) usisif usioif usipf usidc usicnt3 usicnt2 usicnt1 usicnt0 usisr read/write r/w r/w r/w r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
134 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 6 ? usioif: counter overflow interrupt flag this flag is set (one) when the 4-bit counter over flows (i.e., at the transition from 15 to 0). an interrupt will be generated when the flag is set while the usioie bit in usicr and the global interrupt enable flag are set. the flag is cleared if a one is written to the usioif bit or by reading the usibr register. clear ing this bit will release the c ounter overflow hold of scl in two-wire mode. a counter overflow interrup t will wakeup the processor from idle sleep mode. ? bit 5 ? usipf: stop condition flag when two-wire mode is selected, the usipf flag is set (one) when a stop condition is detected. the flag is cleared by writing a one to this bit. note that this is not an interrupt flag. this signal is useful when implementing two-wire bus master arbitration. ? bit 4 ? usidc: data output collision this bit is logical one when bit 7 in the shift re gister differs from the physical pin value. the flag is only valid when two-wire mode is used . this signal is useful when implementing two-wire bus master arbitration. ? bits 3..0 ? usicnt3..0: counter value these bits reflect the current 4-bit counter val ue. the 4-bit counter value can directly be read or written by the cpu. the 4-bit counter increments by one for each clock generated either by the external clock edge detector, by a timer/counter0 compare matc h, or by software using usiclk or usitc strobe bits. the clock source depends of the sett ing of the usics1..0 bits. for external clock operation a special feature is added that allows the clock to be generated by writing to the usitc strobe bit. this feature is enabled by write a one to the usiclk bit while setting an external clock source (usics1 = 1). note that even when no wire mode is selected (usiwm1..0 = 0) the external clock input (usck/scl) are can still be used by the counter. 4.18.5.4 usicr ? usi control register the control register includes interrupt enable control, wire mode setting, clock select setting, and clock strobe. ? bit 7 ? usisie: start condition interrupt enable setting this bit to one enables the start condition detector interrupt. if there is a pending inter- rupt when the usisie a nd the global inte rrupt enable flag is set to one, this will immediately be executed. see the usisif bit description in ?usisr ? usi status register? on page 133 for further details. bit 7 6 5 4 3 2 1 0 0x0d (0x2d) usisie usioie usiwm1 usiwm0 us ics1 usics0 usiclk usitc usicr read/write r/w r/w r/w r/w r/w r/w w w initial value 0 0 0 0 0 0 0 0
135 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 6 ? usioie: counter overflow interrupt enable setting this bit to one enables the counter overflow interrupt. if there is a pending interrupt when the usioie and the global interrupt enable flag is set to one, this will immediately be executed. see the usioif bit description in ?usisr ? usi status register? on page 133 for further details. ? bit 5..4 ? usiwm1..0: wire mode these bits set the type of wire mode to be used. basically only the function of the outputs are affected by these bits. data and clock inputs are not affected by the mode selected and will always have the same function. the counter and shift register can therefore be clocked externally, and data input sampled, even when outputs are disabled. the relations between usiwm1..0 and the usi operation is summarized in table 4-44 . note: 1. the di and usck pins are renamed to serial data (sda) and serial clock (scl) respec- tively to avoid confusion between the modes of operation. table 4-44. relations between usiwm1..0 and the usi operation usiwm1 usiwm0 description 00 outputs, clock hold, and start detector disabled. port pins operates as normal. 01 three-wire mode. uses do, di, and usck pins. the data output (do) pin overrides the corresponding bit in the port register in this mode. however, the corresponding ddr bit still controls the data direction. when the port pin is set as input the pins pull-up is controlled by the port bit. the data input (di) and serial clock (usck) pins do not affect the normal port operation. when operating as master, clock pulses are software generated by toggling the port register , while the data direction is set to output. the usitc bit in the usicr regi ster can be used for this purpose. 10 two-wire mode. uses sda (di) and scl (usck) pins (1) . the serial data (sda) and the serial clock (scl) pins are bi-directional and uses open-collector output drives. the output drivers are enabled by setting the corresponding bit for sda and scl in the ddr register. when the output driver is enabled fo r the sda pin, the output driver will force the line sda low if the output of the shift register or the corresponding bit in the port register is zero. otherwise the sda line will not be driven (i.e., it is released). when the scl pin output driver is enabled the scl line will be forced low if the corresponding bit in the port register is zero, or by the start detector. otherwise the scl line will not be driven. the scl line is held low when a start detector detects a start condition and the output is enabled. clearing the st art condition flag (usisif) releases the line. the sda and scl pin inputs is not affected by enabling this mode. pull-ups on the sda and scl port pin are disabled in two-wire mode. 11 two-wire mode. uses sda and scl pins. same operation as for the two-wire mode described above, except that the scl line is also held low when a counter overflow occurs, and is held low until the counter overflow flag (usioif) is cleared.
136 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 3..2 ? usics1..0: clock source select these bits set the clock source for the shift register and counter. the data output latch ensures that the output is changed at the opposite edge of the sampling of the data input (di/sda) when using external clock sour ce (usck/scl). when software strobe or timer/counter0 compare match clock option is selected, the output latch is transparent and therefore the output is changed immediately. clearing the usics1..0 bits enables software strobe option. when using this option, writing a one to the usiclk bit clocks both the shift register and the counter. for external clock so urce (usics1 = 1), the usiclk bit is no longer used as a strobe, but selects between external clocking and software clocking by the usitc strobe bit. table 4-45 shows the relationship between the usics1..0 and usiclk setting and clock source used for the shift register and the 4-bit counter. ? bit 1 ? usiclk: clock strobe writing a one to this bit location strobes the shift register to shift one step and the counter to increment by one, provided that the usics1..0 bits are set to zero and by doing so the soft- ware clock strobe option is selected. the ou tput will change immediately when the clock strobe is executed, i.e., in the same instructi on cycle. the value shifted into the shift register is sampled the previous instruction cycle. the bit will be read as zero. when an external clock source is selected (usics1 = 1), the usiclk function is changed from a clock strobe to a clock select register. setting the usiclk bit in this case will select the usitc strobe bit as clock source for the 4-bit counter (see table 4-45 ). ? bit 0 ? usitc: toggle clock port pin writing a one to this bit location toggles the usck/scl value either from 0 to 1, or from 1 to 0. the toggling is independent of the setting in the data direction register, but if the port value is to be shown on the pin the ddre4 must be set as output (to one). th is feature allows easy clock generation when impl ementing master devices. th e bit will be read as zero. when an external clock source is selected (usics1 = 1) and the usiclk bit is set to one, writ- ing to the usitc strobe bit will directly clock th e 4-bit counter. this allo ws an early detection of when the transfer is done when operating as a master device. table 4-45. relations between the usics1..0 and usiclk setting usics1 usics0 usiclk shift register cl ock source 4-bit counter clock source 0 0 0 no clock no clock 001 software clock strobe (usiclk) software clock strobe (usiclk) 01x timer/counte r0 compare match timer/counter0 compare match 1 0 0 external, positive edge external, both edges 1 1 0 external, negative edge external, both edges 1 0 1 external, positive edge software clock strobe (usitc) 1 1 1 external, negative edge software clock strobe (usitc)
137 9137e?rke?12/10 atmel ATA5771/73/74 4.19 analog comparator the analog comparator compares the input val ues on the positive pin ain0 and negative pin ain1. when the voltage on the positive pin ain0 is higher than the voltage on the negative pin ain1, the analog comparator output, aco, is set. the comparator can trigger a separate interrupt, exclusive to the analog comparator. the user can select interrupt triggering on com- parator output rise, fall or toggle. a block diagram of the comparator and its surrounding logic is shown in figure 4-58 . figure 4-58. analog comparator block diagram (1) note: 1. see table 4-46 . 4.19.1 analog comparator multiplexed input when the analog to digital conv erter (adc) is configurated as single ended input channel, it is possible to select any of the adc7..0 pins to replace the negative input to the analog com- parator. the adc multiplexer is used to select this input, and consequently, the adc must be switched off to utilize this feature. if the analog comparator multiplexer enable bit (acme in adcsrb) is set and the adc is switched off (a den in adcsra is zero), mux1..0 in admux select the input pin to replace the negative input to the analog comparator, as shown in table 4-46 . if acme is cleared or aden is set, ain1 is applied to the negative input to the analog comparator. acbg bandgap reference adc multiplexer output acme aden (1) table 4-46. analog comparator multiplexed input acme aden mux4..0 analog co mparator negative input 0x xxain1 11 xxain1 1 0 00000 adc0 1 0 00001 adc1 1 0 00010 adc2 1 0 00011 adc3 1 0 00100 adc4 1 0 00101 adc5 1 0 00110 adc6 1 0 00111 adc7
138 9137e?rke?12/10 atmel ATA5771/73/74 4.19.2 register description 4.19.2.1 adcsrb ? adc control and status register b ? bit 6 ? acme: analog comparator multiplexer enable when this bit is writte n logic one and the adc is switched off (aden in adcsra is zero), the adc multiplexer selects the negati ve input to the analog comparator. when this bit is written logic zero, ain1 is applied to the negative in put of the analog comparator. for a detailed description of this bit, see section 4.19.1 ?analog comparator multiplexed input? on page 137 . 4.19.2.2 acsr ? analog comparator control and status register ? bit 7 ? acd: analog comparator disable when this bit is written logic one, the power to the analog comparator is switched off. this bit can be set at any time to tu rn off the analog comparator. th is will reduce power consumption in active and idle mode. when changing the acd bit, the analog comparator interrupt must be disabled by clearing the acie bit in acsr . otherwise an interrupt can occur when the bit is changed. ? bit 6 ? acbg: analog comparator bandgap select when this bit is set, a fixed bandgap referenc e voltage replaces the positive input to the ana- log comparator. when this bit is cleared, ain0 is applied to the positive input of the analog comparator. ? bit 5 ? aco: analog comparator output the output of the analog comparator is sy nchronized and then directly connected to aco. the synchronization introduces a delay of 1 - 2 clock cycles. ? bit 4 ? aci: analog comparator interrupt flag this bit is set by hardware when a comparator output event triggers the interrupt mode defined by acis1 and acis0. the analog comparator interrupt routine is executed if the acie bit is set and the i-bit in sreg is set. aci is cleare d by hardware when executing the corresponding interrupt handling vector. alternatively, aci is cleared by writing a logic one to the flag. ? bit 3 ? acie: analog comparator interrupt enable when the acie bit is written logic one and the i- bit in the status register is set, the analog comparator interrupt is activated. when written logic zero, the interrupt is disabled. bit 7 6543210 0x03 (0x23) bin acme ? adlar ? adts2 adts1 adts0 adcsrb read/write r/w r/w r r/w r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x08 (0x28) acd acbg aco aci acie acic acis1 acis0 acsr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 n/a 0 0 0 0 0
139 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 2 ? acic: analog comparator input capture enable when written logic one, this bit enables the input capture function in timer/counter1 to be trig- gered by the analog comparator. the comparator output is in this case directly connected to the input capture front-end logi c, making the compar ator utilize the noise canceler and edge select features of the timer/counter1 input capture interrupt. when written logic zero, no con- nection between the analog comparator and the input capture function exists. to make the comparator trigger the timer/counter1 input capture inter-rupt, the icie1 bit in the timer interrupt mask register (timsk1) must be set. ? bits 1, 0 ? acis1, acis0: analog comparator interrupt mode select these bits determine which comparator events that trigger the analog comparator interrupt. the different settings are shown in table 4-47 . when changing the acis1/acis0 bits, the analog comparator interrupt must be disabled by clearing its interrupt enable bit in the acsr register. otherwise an interrupt can occur when the bits are changed. 4.19.2.3 didr0 ? digital input disable register 0 ? bits 1, 0 ? adc0d,adc1d: adc 1/ 0 digital input buffer disable when this bit is written logic one, the digital in put buffer on the ain1/0 pin is disabled. the cor- responding pin register bit will always read as zero when this bit is set. when an analog signal is applied to the ain1/0 pin and the digi tal input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. table 4-47. acis1/acis0 settings acis1 acis0 interrupt mode 0 0 comparator interrupt on output toggle. 01reserved 1 0 comparator interrupt on falling output edge. 1 1 comparator interrupt on rising output edge. bit 76543210 0x01 (0x21) adc7d adc6d adc5d adc4d adc3d adc2d adc1d adc0d didr0 read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value 0 0 0 0 0 0 0 0
140 9137e?rke?12/10 atmel ATA5771/73/74 4.20 analog to digital converter 4.20.1 features ? 10-bit resolution ? 1.0lsb integral non-linearity ? 2 lsb absolute accuracy ? 65 - 260s conversion time ? up to 76ksps at maximum resolution ? eight multiplexed single ended input channels ? twelve differential input channels with selectable gain (1x, 20x) ? temperature sensor input channel ? optional left adjustment for adc result readout ? 0 - v cc adc input voltage range ? 1.1v adc reference voltage ? free running or single conversion mode ? adc start conversion by auto tr iggering on interrupt sources ? interrupt on adc conversion complete ? sleep mode no ise canceler ? unipolar / bipolar input mode ? input polarity reversal channels 4.20.2 overview the atmel ? attiny44v features a 10-bit successive approximation adc. the adc is con- nected to 8-pin port a for external sources. in addition to external sources internal temperature sensor can be measured by adc. analog mult iplexer allows eight single-ended channels or 12 differential channels from port a. the programmable gain stage provides ampification steps 0 db (1x) and 26 db (20x) for 12 differential adc channels. the adc contains a sample and hold circuit wh ich ensures that the input voltage to the adc is held at a constant level during conversion. a block diagram of the adc is shown in figure 4-59 on page 141 . internal reference voltage of nominally 1.1v is provided on-chip. alternatively, v cc can be used as reference voltage for single ended chan nels. there is also an option to use an exter- nal voltage reference and turn-off the internal voltage reference.
141 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-59. analog to digital converter block schematic 4.20.3 adc operation the adc converts an analog input voltage to a 10-bit digital value through successive approx- imation. the minimum value represents gnd and the maximum value represents the reference voltage.the voltage reference for the adc may be selected by writing to the refs1..0 bits in admux. the vcc supply, the aref pin or an internal 1.1v voltage refer- ence may be selected as the adc voltage reference. the analog input channel and differential gain are se lected by writing to the mux5..0 bits in admux. any of the eight adc input pins adc7..0 can be selected as single ended inputs to the adc. for differential measurements all analog inputs next to each other can be selected as a input pair. every input is also possible to measure with adc3. these pairs of differential inputs are measured by adc trough the differential gain amplifier. adc co nv ersio n complete irq 8 -bit data bus 15 0 adc multiplexer select (admux) adc ctrl. & status a register (adcsra) adc data register (adch/adcl) adie adate adsc ade n adif adif mux4...mux0 adps0 adps1 adps2 co nv ersio n logic 10-bit dac + - sample & hold comparator i n ter n al refere n ce 1.1 v mux decoder v cc adc7 adc6 adc5 adc4 refs1..refs0 adlar cha nn el selectio n adc[9:0] adc multiplexer output prescaler trigger select adts2...adts0 i n terrupt flags start + - gai n selectio n gai n amplifier neg. input mux si n gle e n ded / differe n tial selectio n temperature se n sor adc 8 bi n ipr adc3 adc2 adc1 adc0 pos. input mux ag n d adc ctrl. & status b register (adcsrb) aref
142 9137e?rke?12/10 atmel ATA5771/73/74 if differential channels are selected, the differential gain stage amplifies the voltage difference between the selected input pair by the selected gain factor, 1x or 20x, according to the setting of the mux0 bit in admux. this amplified value then becomes the analog input to the adc. if single ended channels are used, the gain amplifier is bypassed altogether. the offset of the differential channels can be measure by selecting the same input for both negative and positive input. offset calibration can be done for adc0, adc3 and adc7. when adc0 or adc3 or adc7 is selected as both the positive and negative input to the differential gain amplifier , the remaining offset in t he gain stage and conversion circuitry can be mea- sured directly as the result of the conversion. this figure can be subtracted from subsequent conversions with the same gain setting to reduce offset error to below 1 lsb. the on-chip temperature sensor is selected by writing the code ?100010? to the mux5..0 bits in admux register. the adc is enabled by setting the adc enable bit, aden in adcsra. voltage reference and input channel se lections will not go into ef fect until aden is set. the adc does not consume power when aden is cleared, so it is recommended to switch off the adc before entering power saving sleep modes. the adc generates a 10-bit result which is presented in the adc data registers, adch and adcl. by default, the result is presented ri ght adjusted, but can optionally be presented left adjusted by setting the adlar bit in adcsrb. if the result is left adjusted and no more than 8-bi t precision is required, it is sufficient to read adch. otherwise, adcl must be read first, then adch, to ensure that the content of the data registers belongs to the same conversion. once adcl is read, adc access to data registers is blocked. this means that if adcl has been read, and a conversion completes before adch is read, neither register is updated and the re sult from the conversi on is lost. when adch is read, adc access to the adch and adcl registers is re-enabled. the adc has its own interrupt which can be triggered when a conversion completes. when adc access to the data registers is prohibited between reading of adch and adcl, the inter- rupt will trigger even if the result is lost. 4.20.4 starting a conversion a single conversion is started by writing a lo gical one to the adc start conversion bit, adsc. this bit stays high as long as the conversion is in progress and will be cleared by hardware when the conversion is completed. if a different data channel is selected while a conversion is in progress, the adc will finish the current conversion befo re performing t he channel change. alternatively, a conversion can be triggered automatically by various sources. auto triggering is enabled by setting the adc auto trigger en able bit, adate in adcsra. the trigger source is selected by setting the adc trigger select bits, adts in a dcsrb (see description of the adts bits for a list of the trigger sources). when a positive edge occurs on the selected trigger signal, the adc prescaler is reset and a conversion is started. this provides a method of start- ing conversions at fixed intervals. if the trigger signal still is set when the conversion completes, a new conversion will no t be started. if another positi ve edge occurs on the trigger signal during conversion, the ed ge will be ignored. note that an interrupt flag will be set even if the specific interrupt is disabled or the globa l interrupt enable bit in sreg is cleared. a con- version can thus be triggered without causing an interrupt. however, the interrupt flag must be cleared in order to trigger a new conversion at the next interrupt event.
143 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-60. adc auto trigger logic using the adc interrupt flag as a trigger s ource makes the adc start a new conversion as soon as the ongoing conversion has finished. th e adc then operates in free running mode, constantly sampling and updating the adc data r egister. the first conversion must be started by writing a logical one to the adsc bit in adcsra. in this mode the adc will perform suc- cessive conversions independently of whether the adc interrupt flag, adif is cleared or not. if auto triggering is enabled, single conversi ons can be started by writing adsc in adcsra to one. adsc can also be used to determine if a conv ersion is in progress. the adsc bit will be read as one during a conversion, independently of how the conversion was started. 4.20.5 prescaling and conversion timing figure 4-61. adc prescaler by default, the successive approximation circui try requires an input clock frequency between 50 khz and 200 khz to get maximum resolution. if a lower resolution than 10 bits is needed, the input clock frequency to the adc can be higher than 200 khz to get a higher sample rate. adsc adif source 1 source n adts[2:0] conversion logic prescaler start clk adc . . . . edge detector adate 7-bit adc prescaler adc clock source ck adps0 adps1 adps2 ck/128 ck/2 ck/4 ck/8 ck/16 ck/32 ck/64 reset aden start
144 9137e?rke?12/10 atmel ATA5771/73/74 the adc module contains a prescaler, which generates an acceptable adc clock frequency from any cpu frequency above 100 khz. the pr escaling is set by the adps bits in adcsra. the prescaler starts counting from the moment the adc is switched on by setting the aden bit in adcsra. the prescaler keeps running for as long as the aden bit is set, and is contin- uously reset when aden is low. when initiating a single ended conversion by setting the adsc bit in adcsra, the conversion starts at the following rising edge of the adc clock cycle. a normal conversion takes 13 adc clock cycles . the first conversion after the adc is switched on (aden in adcsra is set) takes 25 adc clock cycles in order to initialize the ana- log circuitry. the actual sample-and-hold take s place 1.5 adc clock cycles afte r the start of a normal con- version and 14.5 adc clock cycles after the start of an first conversion. when a conversion is complete, the result is written to the adc data registers, and adif is set. in single conver- sion mode, adsc is cleared simultaneously. the software may then set adsc again, and a new conversion will be in itiated on the first ri sing adc clock edge. when auto triggering is used, the prescaler is reset when the trigger event occurs. this assures a fixed delay from the trigger event to the start of conversion. in this mode, the sam- ple-and-hold takes place two adc clock cycles after the rising edge on the trigger source signal. three additional cpu clock cycles are used for synchronization logic. in free running mode, a new conversion will be started immediately after the conversion completes, while adsc remains high. fo r a summary of conversion times, see table 4-48 on page 146 . figure 4-62. adc timing diagram, first conver sion (single conversion mode) sign and msb of result lsb of result adc clock adsc sample & hold adif adch adcl cycle number aden 1 212 13 14 15 16 17 18 19 20 21 22 23 24 25 1 2 first conversion next conversion 3 mux and refs update mux and refs update conversion complete
145 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-63. adc timing diagram, single conversion figure 4-64. adc timing diagram, auto triggered conversion figure 4-65. adc timing diagram, free running conversion 1 2 3 4 5 6 7 8 9 10 11 12 13 sign and msb of result lsb of result adc clock adsc adif adch adcl cycle number 12 one conversion next conversion 3 sample & hold mux and refs update conversion complete mux and refs update 1 2 3 4 5 6 7 8 9 10 11 12 13 sign and msb of result lsb of result adc clock trigger source adif adch adcl cycle number 12 one conversion next conversion conversion complete prescaler reset adate prescaler reset sample & hold mux and refs update 11 12 13 sign and msb of result lsb of result adc clock adsc adif adch adcl cycle number 12 one conversion next conversion 34 conversion complete sample & hold mux and refs update
146 9137e?rke?12/10 atmel ATA5771/73/74 4.20.6 changing channel or reference selection the mux5:0 and refs1:0 bits in the admux r egister are single buffered through a tempo- rary register to which the cpu has random access. this ensures that the channels and reference selection only takes place at a sa fe point during the c onversion. the channel and reference selection is continuously updated until a conversion is started. once the conversion starts, the channel and reference selection is locked to ensure a sufficient sampling time for the adc. continuous updating resumes in th e last adc clock cycle before the conversion completes (adif in adcsra is set). note that the conversion starts on the following rising adc clock edge after adsc is written. the user is thus advised not to write new channel or reference selection values to admux until on e adc clock cycle after adsc is written. if auto triggering is used, the exact time of t he triggering event can be indeterministic. special care must be taken when updating the admux register, in order to control which conversion will be affected by the new settings. if both adate and aden is written to one, an interrupt event can occur at any time. if the admux register is changed in this period, the us er cannot tell if the next conversion is based on the old or the new settings. admux can be safely updated in the following ways: a. when adate or aden is cleared. b. during conversion, minimum one adc clock cycle after the trigger event. c. after a conversion, before the interrupt flag used as trigger source is cleared. when updating admux in one of these conditio ns, the new settings will affect the next adc conversion. 4.20.6.1 adc input channels when changing channel selections, the user should observe the following guidelines to ensure that the correct channel is selected: in single conversion mode, always select the channel before starting the conversion. the channel selection may be changed one adc cloc k cycle after writing one to adsc. however, the simplest method is to wait for the conversion to complete before changing the channel selection. in free running mode, always select the channel before starting the first conversion. the channel selection may be changed one adc cloc k cycle after writing one to adsc. however, the simplest method is to wait for the first conversion to complete, and then change the chan- nel selection. since the next c onversion has already started aut omatically, the next result will reflect the previous channel selection. subsequent conversions will reflect the new channel selection. table 4-48. adc conversion time condition sample & hold (cycles from start of conversion) conversion time (cycles) first conversion 14.5 25 normal conversions 1.5 13 auto triggered conversions 2 13.5
147 9137e?rke?12/10 atmel ATA5771/73/74 4.20.6.2 adc voltage reference the reference voltage for the adc (v ref ) indicates the conversion range for the adc. single ended channels that exceed v ref will result in codes close to 0x3ff. v ref can be selected as either v cc , or internal 1.1v reference, or external aref pin. the first adc conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result. 4.20.7 adc noise canceler the adc features a noise canceler that enables conversion during sleep mode to reduce noise induced from the cpu core and other i/o peripherals. the noise canceler can be used with adc noise reduction and idle mode. to make use of this feature, the following proce- dure should be used: a. make sure that the adc is enabled and is not busy converting. single conversion mode must be selected and the adc conversion complete interrupt must be enabled. b. enter adc noise reduction mode (or idle mode). the adc will start a conversion once the cpu has been halted. c. if no other interrupts occur before the adc conversion completes, the adc inter- rupt will wake up the cpu and execute the adc conversion complete interrupt routine. if another interrupt wakes up the cpu before the adc conversion is com- plete, that interrupt will be executed, and an adc conversion complete interrupt request will be generated when the adc conversion completes. the cpu will remain in active mode until a new sleep command is executed. note that the adc will not be automatically turned off when entering other sleep modes than idle mode and adc noise reduction mode. the user is advised to write zero to aden before entering such sleep modes to av oid excessive power consumption. 4.20.7.1 analog input circuitry the analog input circuitry for single ended channels is illustrated in figure 4-66 . an analog source applied to adcn is subjected to t he pin capacitance and input leakage of that pin, regardless of whether that channel is select ed as input for the adc. when the channel is selected, the source must drive the s/h c apacitor through the series resistance (combined resistance in the input path). the adc is optimized for analog signals with an output impedance of approximately 10 k or less. if such a source is used, the sampling time will be negligible. if a source with higher impedance is used, the sampling time will depend on how long time the source needs to charge the s/h capacitor, with can vary widely. the user is recommended to only use low impedant sources with slowly varying signals, si nce this minimizes the required charge trans- fer to the s/h capacitor. signal components higher than the nyquist frequency (f adc /2) should not be present to avoid distortion from unpredictable signal convolution. the user is advised to remove high frequency components with a low-pass filter before applying the signals as inputs to the adc.
148 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-66. analog input circuitry 4.20.7.2 analog noise canceling techniques digital circuitry inside and outside the device generates emi which might affect the accuracy of analog measurements. if conversion accuracy is critical, the noise level can be reduced by applying the following techniques: a. keep analog signal paths as short as possible. make sure analog tracks run over the analog ground plane, and keep them well away from high-speed switching digi- tal tracks. b. use the adc noise canceler function to reduce induced noise from the cpu. c. if any port pins are used as digital outputs, it is essential that these do not switch while a conversion is in progress. 4.20.7.3 adc accuracy definitions an n-bit single-ended adc converts a voltage linearly between gnd and v ref in 2 n steps (lsbs). the lowest code is read as 0, and the highest code is read as 2 n -1. several parameters describe the deviation from the ideal behavior: ? offset: the deviation of the first transition (0x000 to 0x001) compared to the ideal transition (at 0.5 lsb). ideal value: 0 lsb. figure 4-67. offset error adcn i ih 1..100 k c s/h = 14 pf v cc /2 i il output code v ref input voltage ideal adc actual adc offset error
149 9137e?rke?12/10 atmel ATA5771/73/74 ? gain error: after adjusting for offset, the gain error is found as the deviation of the last transition (0x3fe to 0x3ff) compared to the ideal transition (at 1.5 lsb below maximum). ideal value: 0 lsb figure 4-68. gain error ? integral non-linearity (inl): after adjusting for offset and gain error, the inl is the maximum deviation of an actual transition compared to an ideal transition for any code. ideal value: 0 lsb. figure 4-69. integral non-linearity (inl) ? differential non-linearity (dnl): the maximum devi ation of the actual code width (the interval between two adjacent transitions) from the ideal code width (1 lsb). ideal value: 0 lsb. output code v ref input voltage ideal adc actual adc gain error output code v ref input voltage ideal adc actual adc inl
150 9137e?rke?12/10 atmel ATA5771/73/74 figure 4-70. differential non-linearity (dnl) ? quantization error: due to the quantization of the input voltage into a finite number of codes, a range of input voltages (1 lsb wide) will code to the same value. always 0.5 lsb. ? absolute accuracy: the maximum deviation of an actual (unadjusted) transition compared to an ideal transition for any code. this is the compound effect of offset, gain error, differential error, non-linearity, and quantization error. ideal value: 0.5 lsb. 4.20.8 adc conversion result after the conversion is complete (adif is high), the conversion result can be found in the adc result registers (adcl, adch). the form of the conversion result depends on the type of the conversio as there are three types of conversion s: single ended conversion, unipolar differen- tial conversion and bipolar differential conversion. 4.20.8.1 single ended conversion for single ended conversion, the result is where v in is the voltage on the selected input pin and v ref the selected voltage reference (see table 4-50 on page 152 and table 4-51 on page 153 ). 0x000 represents analog ground, and 0x3ff represents the selected reference voltage minus one lsb. the result is presented in one-sided form, from 0x3ff to 0x000. output code 0x3ff 0x000 0 v ref input voltage dnl 1 lsb adc v in 1024 ? v ref ----------------------------- =
151 9137e?rke?12/10 atmel ATA5771/73/74 4.20.8.2 unipolar differential conversion if differential channels and an unipolar input mode are used, the result is where v pos is the voltage on the positive input pin, v neg the voltage on the negative input pin, and v ref the selected voltage reference. the voltage of the positive pin must always be larger than the voltage of the negative pin or otherwise the voltage difference is saturated to zero. the result is presented in one-sided form, from 0x000 (0d) through 0x3ff (+1023d). the gain is either 1x or 20x. 4.20.8.3 bipolar differential conversion if differential channels and a bipolar input mode are used, the result is where v pos is the voltage on the positive input pin, v neg the voltage on the negative input pin, and v ref the selected voltage reference. the result is presented in two?s complement form, from 0x200 (-512d) through 0x1ff (+511d). the gain is either 1x or 20x. note that if the user wants to perform a quick polarity check of the result, it is sufficient to read the msb of the result (adc9 in adch). if the bit is one, the result is negative, and if this bit is zero, the result is positive. as default the adc converter operates in the unipolar input mode, but the bipolar input mode can be selected by writting the bin bit in the adcsrb to one. in the bipolar input mode two-sided voltage differences are allowed and thus the voltage on the negative input pin can also be larger than the voltage on the positive input pin. 4.20.9 temperature measurement the temperature measurement is based on an on-chip temperature sensor that is coupled to a single ended adc8 channel. selecting the adc8 channel by writing the mux5:0 bits in admux register to ?100010? enables the temperature sensor. the internal 1.1v reference must also be selected for the adc reference source in the temperature sensor measurement. when the temperature sensor is enabled, the adc converter can be used in single conversion mode to measure the voltage over the temperature sensor. the measured voltage has a linear relationship to the temperature as described in table 51. the voltage sensitivity is approxi- mately 1 mv / c and the accuracy of the temperature measurement is +/- 10 c after offset calibration. bandgap is always calibrated and its accuracy is only guaranteed between 1.0v and 1.2v adc v pos v neg ? () 1024 ? v ref ---------------------------------------------------------- - gain ? = adc v pos v neg ? () 512 ? v ref ------------------------------------------------------- gain ? = table 4-49. temperature vs. sensor output voltage (typical case) temperature / c -40c +25c +85c +125c voltage / mv 243 mv 314 mv 380 mv 424 mv
152 9137e?rke?12/10 atmel ATA5771/73/74 the values described in table 4-49 on page 151 are typical values. however, due to the pro- cess variation the temperature sensor output voltage varies from one chip to another. to be capable of achieving more accurate results the temperature measurement can be calibrated in the application software. the software calibration requires that a calibration value is measured and stored in a register or eeprom for each chip, as a part of the producti on test. the sof- ware calibration can be done utilizing the formula: t = {[(adch << 8) | adcl] - tos} / k where adcn are the adc data registers, k is a fixed coefficient and t os is the temperature sensor offset value determined and stored into eeprom as a part of the production test.to obtain best accuracy the coefficient k should be measured using two temperature calibrations. using offset calibration, set k = 1.0, where k = (1024*1.07mv/c)/1.1v~1.0 [1/c]. 4.20.10 register description 4.20.10.1 admux ? adc mult iplexer selection register ? bit 7:6 ? refs1:refs0: reference selection bits these bits select the voltage reference for the adc, as shown in table 4-50 on page 152 . if these bits are changed during a conversion, the change will not go in effect until this conversion is complete (adif in adcsr is set). special care should be taken when changing differential channels. once a differential channel has been selected, the st age may take as much as 25 adc clock cycles to stabilize to the new value. thus conversions should not be started within the first 13 clock cycles after selecting a new differential channel. alternatively, conversi on results obtained within this period should be discarded. the same settling time should be observed for the first differential conversion after changing adc reference (by changing the refs1:0 bits in admux). if channels where differential gain is used ie. the gainstage, using v cc or an optional external aref higher than (v cc - 1v) is not recommended, as this will affect adc accuracy. it is not allowed to connect internal voltage reference to aref pin, if an external voltage is being applied to it already. internal voltage reference is connected aref pin when refs1:0 is set to value ?11?. bit 76543210 0x07 (0x27) refs1 refs0 mux5 mux4 mux3 mux2 mux1 mux0 admux read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value 0 0 0 0 0 0 0 0 table 4-50. voltage reference selections for adc refs1 refs0 voltage reference selection 00v cc used as analog reference, disconnected from pa0 (aref). 01 external voltage reference at pa0 (aref) pin, internal voltage reference turned off. 1 0 internal 1.1v voltage reference. 1 1 reserved.
153 9137e?rke?12/10 atmel ATA5771/73/74 ? bits 5:0 ? mux5:0: analog channel and gain selection bits the value of these bits selects which combination of analog inputs are connected to the adc. in case of differential input , gain selection is also made with these bits. selections on table 4-51 show values for single endid channels and where the the differential channels as well as the offset calibration selections are lo cated. selecting the single-ended channel adc8 enables the temperature measurement. see table 4-51 for details. if these bits are changed during a conversion, the change will not go into ef fect until this conversion is complete (adif in adcsra is set). notes: 1. see table 4-52 on page 154 for details. 2. section 4.20.9 ?temperature measurement? on page 151 3. for offset calibration only .see table 4-52 on page 154 and section 4.20.3 ?adc operation? on page 141 see table 4-52 on page 154 for details of selections of differential input channel selections as well as selections of offset calibration channels. mux0 bit works as a gain selection bit for dif- ferential channels shown in table 4-52 on page 154 . when mux0 bit is cleared (?0?) 1x gain is selected and when it is set (?1?) 20x gain is selected. for normal differential channel pairs mux5 bit work as a polarity reversal bit. togling of the mux5 bi t exhanges the positive and negative channel other way a round. for offset calibration purpose the offset of the certain differential channels can be measure by selecting the same input for both negative and positive input. this calibration can be done for adc0, adc3 and adc7. section 4.20.3 ?adc operation? on page 141 describes offset cali- bration in a more detailed level. table 4-51. single endid input channel selections. single ended input mux5..0 adc0 (pa0) 000000 adc1 (pa1) 000001 adc2 (pa2) 000010 adc3 (pa3) 000011 adc4 (pa4) 000100 adc5 (pa5) 000101 adc6 (pa6) 000110 adc7 (pa7) 000111 reserved for differential channels (1) 001000 - 011111 0v (agnd) 100000 1.1v (i ref) 100001 adc8 (2) 100010 reserved for offset calibration (3) 100011 - 100111 reserved for reversal differential channels (1) 101000 - 111111
154 9137e?rke?12/10 atmel ATA5771/73/74 table 4-52. differential input ch annel selections. positive differential input negative differential input mux5..0 gain 1x gain 20x adc0 (pa0) adc0 (pa0) (1) 1. for offset calibration only .see section 4.20.3 ?adc operation? on page 141 n/a 100011 adc1 (pa1) 001000 001001 adc3 (pa3) 001010 001011 adc1 (pa1) adc0 (pa0) 101000 101001 adc2 (pa2) 001100 001101 adc3 (pa3) 001110 001111 adc2 (pa2) adc1 (pa1) 101100 101101 adc3 (pa3) 010000 010001 adc3 (pa3) adc0 (pa0) 101010 101011 adc1 (pa1) 101110 101111 adc2 (pa2) 110000 110001 adc3 (pa3) (1) 100100 100101 adc4 (pa4 010010 010011 adc5 (pa5) 010100 010101 adc6 (pa6) 010110 010111 adc7 (pa7) 011000 011001 adc4 (pa4 adc3 (pa3) 110010 110011 adc5 (pa5) 011010 011011 adc5 (pa5) adc3 (pa3) 110100 110101 adc4 (pa4) 111010 111011 adc6 (pa6) 011100 011101 adc6 (pa6) adc3 (pa3) 110110 110111 adc5 (pa5) 111100 111101 adc7 (pa7) 011110 011111 adc7 (pa7) adc3 (pa3) 111000 111001 adc6 (pa6) 111110 111111 adc7 (pa7) (1) 100110 100111
155 9137e?rke?12/10 atmel ATA5771/73/74 4.20.10.2 adcsra ? adc control and status register a ? bit 7 ? aden: adc enable writing this bit to one en ables the adc. by writing it to zero, the adc is turned off. turning the adc off while a conversion is in prog ress, will terminate this conversion. ? bit 6 ? adsc: adc start conversion in single conversion mode, write this bit to one to start each conversion. in free running mode, write this bit to one to start the first conversion. the first conversion after adsc has been written after the adc has been enabled, or if adsc is written at the same time as the adc is enabled, will take 25 adc clock cycles instead of the normal 13. this first conversion performs initialization of the adc. adsc will read as one as long as a conversi on is in progress. when the conversion is com- plete, it returns to zero. writing zero to this bit has no effect. ? bit 5 ? adate: adc auto trigger enable when this bit is written to on e, auto triggering of the adc is enabled. the adc will start a conversion on a positive edge of the selected trigger signal. the trigger source is selected by setting the adc trigger sele ct bits, adts in adcsrb. ? bit 4 ? adif: adc interrupt flag this bit is set when an adc conversion completes and the data registers are updated. the adc conversion complete interrupt is executed if the adie bit and the i-bit in sreg are set. adif is cleared by hardware when executi ng the corresponding interrupt handling vector. alternatively, adif is cleared by writing a l ogical one to the flag. beware that if doing a read-modify-write on adcsra, a pending interrupt can be disabled. this also applies if the sbi instruction is used. ? bit 3 ? adie: adc interrupt enable when this bit is written to one and the i-bit in sreg is set, the adc conversion complete interrupt is activated. ? bits 2:0 ? adps2:0: adc prescaler select bits these bits determine the division factor between the system clock frequency and the input clock to the adc. bit 76543210 0x06 (0x26) aden adsc adate adif adie adps2 adps1 adps0 adcsra read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
156 9137e?rke?12/10 atmel ATA5771/73/74 4.20.10.3 adcl and adch ? adc data register adlar = 0 adlar = 1 when an adc conversion is complete, the result is found in these two registers. when adcl is read, the adc da ta register is not updated until adch is read. consequently, if the result is left adjusted and no more than 8-bi t precision is required, it is sufficient to read adch. otherwise, adcl must be read first, then adch. the adlar bit in adcsrb, and the muxn bits in admux affect the way the result is read from the registers. if adlar is set, the result is left adjusted. if adlar is cleared (default), the result is right adjusted. ? adc9:0: adc conversion result these bits represent the result from the conversion, as detailed in section 4.20.8 ?adc con- version result? on page 150 . table 4-53. adc prescaler selections adps2 adps1 adps0 division factor 000 2 001 2 010 4 011 8 100 16 101 32 110 64 111 128 bit 151413121110 9 8 0x05 (0x25) ? ? ? ? ? ? adc9 adc8 adch 0x04 (0x24) adc7 adc6 adc5 adc4 adc3 adc2 adc1 adc0 adcl 76543210 read/writerrrrrrrr rrrrrrrr initial value 0 0 0 0 0 0 0 0 00000000 bit 151413121110 9 8 0x05 (0x25) adc9 adc8 adc7 adc6 adc5 adc4 adc3 adc2 adch 0x04 (0x24) adc1 adc0 ? ? ? ? ? ? adcl 76543210 read/writerrrrrrrr rrrrrrrr initial value 0 0 0 0 0 0 0 0 00000000
157 9137e?rke?12/10 atmel ATA5771/73/74 4.20.10.4 adcsrb ? adc control and status register b ? bits 7 ? bin: bipolar input mode the gain stage is working in the unipolar m ode as default, but the bipolar mode can be selected by writing the bin bit in the adcsrb register. in the unipolar mode only one-sided conversions are supported and the voltage on the positive input must always be larger than the voltage on the negative input. otherwise the result is saturated to the voltage reference. in the bipolar mode two-sided conversions are supported and the result is represented in the two?s complement form. in the unipolar mode the resolution is 10 bits and the bipolar mode the resolution is 9 bits + 1 sign bit. ? bit 6 ? acme: analog comparator multiplexer enable see section 4.20.10.4 ?adcsrb ? adc control and status register b? on page 157 . ? bit 5 ? res: reserved bit this bit is reserved bit in the atmel ? attiny44v and will always read as what was wrote there. ? bit 4 ? adlar: adc left adjust result the adlar bit affects the presentation of the adc conversion result in the adc data regis- ter. write one to adlar to left adjust the result. otherwise, the result is right adjusted. changing the adlar bit will affect the adc data register immediately, regardless of any ongoing conversions. for a comple the description of this bit, see section 4.20.10.3 ?adcl and adch ? adc data register? on page 156 . ? bit 3 ? res: reserved bit this bit is reserved bit in the attiny44v and will always read as what was wrote there. ? bits 2:0 ? adts2:0: adc auto trigger source if adate in adcsra is written to one, the valu e of these bits selects which source will trigger an adc conversion. if adate is cleared, the adts2:0 settings will have no effect. a conver- sion will be triggered by the rising edge of the selected interrupt flag. note that switching from a trigger source that is cleared to a trigger source that is set, will gener ate a positive edge on the trigger signal. if aden in adcsra is set, this will start a conversion. switching to free running mode (adts[2:0]=0) will not cause a trigger event, ev en if the adc interrupt flag is set . bit 7 6543210 0x03 (0x23) bin acme ? adlar ? adts2 adts1 adts0 adcsrb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
158 9137e?rke?12/10 atmel ATA5771/73/74 4.20.10.5 didr0 ? digital input disable register 0 ? bits 7..0 ? adc7d..adc0d: adc7..0 digital input disable when this bit is written logic one, the digital input buffer on the corresponding adc pin is dis- abled. the corresponding pin register bit will always read as zero when this bit is set. when an analog signal is applied to the adc7..0 pin an d the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. table 4-54. adc auto trigger source selections adts2 adts1 adts0 trigger source 0 0 0 free running mode 0 0 1 analog comparator 0 1 0 external interrupt request 0 0 1 1 timer/counter0 compare match a 1 0 0 timer/counter0 overflow 1 0 1 timer/counter1 compare match b 1 1 0 timer/counter1 overflow 1 1 1 timer/counter1 capture event bit 76543210 0x01 (0x21) adc7d adc6d adc5d adc4d adc3d adc2d adc1d adc0d didr0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
159 9137e?rke?12/10 atmel ATA5771/73/74 4.21 debugwire on-c hip debug system 4.21.1 features ? complete program flow control ? emulates all on-chip functions, both digital and an alog , except reset pin ? real-time operation ? symbolic debugging support (both at c and assembler source level, or for other hlls) ? unlimited number of prog ram break points (using software break points) ? non-intrusive operation ? electrical characteristics identical to real device ? automatic configuration system ? high-speed operation ? programming of non-volatile memories 4.21.2 overview the debugwire on-chip debug system uses a one- wire, bi-directional interface to control the program flow, execute atmel ? avr ? instructions in the cpu and to program the different non-volatile memories. 4.21.3 physical interface when the debugwire enable (dwen) fuse is programmed and lock bits are unpro- grammed, the debugwire system within the target device is activated. the reset port pin is configured as a wire-and (open-drain) bi-directional i/o pin with pull-up enabled and becomes the communication gateway between target and emulator. figure 4-71. the debugwire setup figure 4-71 shows the schematic of a target mcu, with debugwire enabled, and the emula- tor connector. the system clock is not affected by debugwire and will always be the clock source selected by the cksel fuses. dw gnd dw(reset) vcc 1.8 - 5.5v
160 9137e?rke?12/10 atmel ATA5771/73/74 when designing a system wher e debugwire will be used, the following observations must be made for correct operation: ? pull-up resistor on the dw/(reset) line must be in the ra nge of 10k to 20 k . however, the pull-up resistor is optional. ? connecting the reset pin directly to v cc will not work. ? capacitors inserted on the reset pin must be disconnected when using debugwire. ? all external reset sources must be disconnected. 4.21.4 software break points debugwire supports program memory break points by the atmel ? avr ? break instruction. setting a break point in atmel avr studio ? will insert a break instruction in the program memory. the instruction replac ed by the break instruction will be stored. when program execution is continued, the stor ed instruction will be executed be fore continuing from the pro- gram memory. a break ca n be inserted manually by putti ng the break instruction in the program. the flash must be re-programmed each time a break point is changed. this is automatically handled by avr studio through the debugwire in terface. the use of br eak points will there- fore reduce the flash data retention. devices used for debugging purposes should not be shipped to end customers. 4.21.5 limitations of debugwire the debugwire communication pin (dw) is physically located on the same pin as external reset (reset). an external rese t source is therefore not su pported when the debugwire is enabled. the debugwire system accurately emulates all i/o functions when running at full speed, i.e., when the program in the cpu is running. when the cpu is stopped, care must be taken while accessing some of the i/o registers via the debugger (avr studio). see the debugwire doc- umentation for detailed description of the limitations. a programmed dwen fuse enables some parts of the clock system to be running in all sleep modes. this will increase the power consumption while in sleep. thus, the dwen fuse should be disabled when debugwire is not used. 4.21.6 register description the following section describes the registers used with the debugwire. 4.21.6.1 dwdr ? debugwire data register the dwdr register provides a communication channel from the running program in the mcu to the debugger. this register is only accessible by the debugwire and can therefore not be used as a general purpose register in the normal operations. bit 76543210 0x27 (0x47) dwdr[7:0] dwdr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
161 9137e?rke?12/10 atmel ATA5771/73/74 4.22 self-programming the flash the device provides a self-programming mechanism for downloading and uploading program code by the mcu itself. the self-programming can use any available data interface and asso- ciated protocol to read code and write (program) that code into the program memory. the program memory is updated in a page by page fashion. before programming a page with the data stored in the temporary page buffer, the page must be erased. the temporary page buffer is filled one word at a ti me using spm and the buffer can be filled either before the page erase command or between a page erase and a page write operation: alternative 1, fill the bu ffer before a page erase ? fill temporary page buffer ? perform a page erase ? perform a page write alternative 2, fill the bu ffer after page erase ? perform a page erase ? fill temporary page buffer ? perform a page write if only a part of the page needs to be changed, the rest of the page must be stored (for exam- ple in the temporary page buffer) before the erase, and then be re-written. when using alternative 1, the boot loader provides an effe ctive read-modify-write feature which allows the user software to first read the page, do the necessary changes, and then write back the modified data. if alternative 2 is used, it is not possible to read the old data while loading since the page is already erased. the temporary page buffer can be accessed in a random sequence. it is essential that the page address used in both the page erase and page write operation is addressing the same page. 4.22.1 performing page erase by spm to execute page erase, set up the address in the z-pointer, write ?00000011? to spmcsr and execute spm within four clock cycles after writing spmcsr. the data in r1 and r0 is ignored. the page address must be written to pcpage in the z-register. other bits in the z-pointer will be ignored during this operation. ? the cpu is halted during the page erase operation. 4.22.2 filling the temporary buffer (page loading) to write an instruction word, set up the address in the z-pointer and data in r1:r0, write ?00000001? to spmcsr and execute spm within four clock cycles after writing spmcsr. the content of pcword in the z-register is used to address the data in the temporary buffer. the temporary buffer will auto-erase after a page write operation or by writing the ctpb bit in spmcsr. it is also erased after a system reset. note that it is not possible to write more than one time to each address without erasing the temporary buffer. if the eeprom is written in th e middle of an spm page load operation, all data loaded will be lost.
162 9137e?rke?12/10 atmel ATA5771/73/74 4.22.3 performing a page write to execute page write, set up the address in the z-pointer, write ?00000101? to spmcsr and execute spm within four clock cycles after writing spmcsr. the data in r1 and r0 is ignored. the page address must be written to pcpage. other bits in the z-pointer must be written to zero during this operation. ? the cpu is halted during the page write operation. 4.22.4 addressing the flash during self-programming the z-pointer is used to address the spm commands. since the flash is organized in pages (see table 4-62 on page 169 ), the program counter can be treated as having two different sections. one section, consisting of the least significant bits, is addressing the words within a page, while the most significant bits are addressing the pages. this is shown in figure 4-73 on page 169 . note that the page erase and page write operations are addressed independently. therefore it is of major importance that the software addresses the same page in both the page erase and page write operation. the lpm instruction uses the z-pointer to store the address. since this instruction addresses the flash byte-by-byte, also the lsb (bit z0) of the z-pointer is used. figure 4-72. addressing the flash during spm (1) note: the different variables used in figure 4-72 are listed in table 4-62 on page 169 . bit 151413121110 9 8 zh (r31) z15 z14 z13 z12 z11 z10 z9 z8 zl (r30) z7z6z5z4z3z2z1z0 76543210 program memory 0 1 15 z - register bit 0 zpagemsb word address within a page page address within the flash zpcmsb instruction word pag e pcword[pagemsb:0]: 00 01 02 pageend pag e pcword pcpage pcmsb pagemsb program counter
163 9137e?rke?12/10 atmel ATA5771/73/74 4.22.4.1 eeprom write prev ents writing to spmcsr note that an eeprom write operation will bl ock all software programming to flash. reading the fuses and lock bits from software will also be prevented during th e eeprom write opera- tion. it is recommended that the user checks the status bit (eepe) in the eecr register and verifies that the bit is cleared before writing to the spmcsr register. 4.22.4.2 reading the fuse and lock bits from software it is possible to read both the fuse and lock bits from software. to read the lock bits, load the z-pointer with 0x0001 and set the rflb and spmen bits in spmcsr. when an lpm instruc- tion is executed within three cpu cycles after the rflb and spmen bits are set in spmcsr, the value of the lock bits will be loaded in the destination re gister. the rflb and spmen bits will auto-clear upon completion of reading the lock bits or if no lpm instruction is executed within three cpu cycles or no spm instructi on is executed within four cpu cycles. when rflb and spmen are cleared, lpm will work as described in the in struction set manual. the algorithm for reading the fuse low byte is similar to the one described above for reading the lock bits. to read the fuse low byte, load the z-pointer with 0x0000 and set the rflb and spmen bits in spmcsr. when an lpm instruction is executed within three cycles after the rflb and spmen bits are set in the spmcs r, the value of the fuse low byte (flb) will be loaded in the destination regi ster as shown below. see table 4-60 on page 168 for a detailed description and mapping of the fuse low byte. similarly, when reading the fuse high byte, load 0x0003 in the z-pointer. when an lpm instruction is executed within three cycles af ter the rflb and spmen bits are set in the spmcsr, the value of the fuse high byte (f hb) will be loaded in the destination register as shown below. see table 4-59 on page 167 for detailed description and mapping of the fuse high byte. fuse and lock bits that are pr ogrammed, will be read as zero. fuse and lock bits that are unprogrammed, will be read as one. 4.22.4.3 preventing flash corruption during periods of low v cc , the flash program can be corrupted because the supply voltage is too low for the cpu and the flash to operate properly. these issues are the same as for board level systems using the flash, and the same design solutions should be applied. a flash program corruption can be caused by two situations when the voltage is too low. first, a regular write sequence to the flash requires a minimum voltage to operate correctly. sec- ondly, the cpu itself can execute instructions incorrectly, if the supply voltage for executing instructions is too low. bit 76543210 rd ??????lb2lb1 bit 76543210 rd flb7 flb6 flb5 flb4 flb3 flb2 flb1 flb0 bit 76543210 rd fhb7 fhb6 fhb5 fhb4 fhb3 fhb2 fhb1 fhb0
164 9137e?rke?12/10 atmel ATA5771/73/74 flash corruption can easily be avoided by following these design recommendations (one is sufficient): 1. keep the atmel ? avr ? reset active (low) during peri ods of insufficient power supply voltage. this can be done by enabling the internal brown-out detector (bod) if the operating voltage matches the detection level. if not, an external low v cc reset protec- tion circuit can be used. if a reset occurs while a write operation is in progress, the write operation will be completed provided that the power supply voltage is sufficient. 2. keep the avr core in power-down sleep mode during periods of low v cc . this will pre- vent the cpu from attempting to decode and execute instructions, effectively protecting the spmcsr register and thus the flash from unintentional writes. 4.22.4.4 programming time for flash when using spm the calibrated rc oscillator is used to time flash accesses. table 4-55 shows the typical pro- gramming time for flash accesses from the cpu. note: 1. the min and max programming times is per individual operation. 4.22.5 register description 4.22.5.1 spmcsr ? store program memory control and status register the store program memory control and status register contains the control bits needed to control the program memory operations. ? bits 7..5 ? res: reserved bits these bits are reserved bits in the atmel attiny44v and always read as zero. ? bit 4 ? ctpb: clear temporary page buffer if the ctpb bit is written while filling the te mporary page buffer, the temporary pag e buffer will be cleared and the data will be lost. ? bit 3 ? rflb: read fuse and lock bits an lpm instruction within three cycles after rflb and spmen are set in the spmcsr regis- ter, will read either the lock bits or the fuse bi ts (depending on z0 in the z-pointer) into the destination register. see section 4.22.4.1 ?eeprom write prevents writing to spmcsr? on page 163 for details. table 4-55. spm programming time (1) symbol min programming ti me max programming time flash write (page erase, page write, and write lock bits by spm) 3.7ms 4.5ms bit 7 6 5 4 3 2 1 0 0x37 (0x57) ? ? ? ctpb rflb pgwrt pgers spmen spmcsr read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
165 9137e?rke?12/10 atmel ATA5771/73/74 ? bit 2 ? pgwrt: page write if this bit is written to one at the same time as spmen, the next spm instruction within four clock cycles executes page writ e, with the data stored in the temporary buffer. the page address is taken from the high part of the z-pointer. the data in r1 and r0 are ignored. the pgwrt bit will auto-c lear upon completion of a page write, or if no spm instruction is exe- cuted within four clock cycles. the cpu is halted during the entire page write operation. ? bit 1 ? pgers: page erase if this bit is written to one at the same time as spmen, the next spm instruction within four clock cycles executes page erase. the page address is taken from the high part of the z-pointer. the data in r1 and r0 are ignored . the pgers bit will auto -clear upon completion of a page erase, or if no spm instruction is executed within four clock cycles. the cpu is halted during the entire page write operation. ? bit 0 ? spmen: store program memory enable this bit enables the spm instruction for the nex t four clock cycles. if written to one together with either ctpb, rflb, pgwrt, or pgers, the following spm instruction will have a spe- cial meaning, see description above. if only spm en is written, the fo llowing spm instruction will store the value in r1:r0 in the temporary page buffer addressed by the z-pointer. the lsb of the z-pointer is ignor ed. the spmen bit will auto-clear upon completion of an spm instruction, or if no spm instruction is exec uted within four clock cycles. during page erase and page write, the spmen bit remains high until the operation is completed. writing any other combination than ?10001?, ?01001?, ?00101?, ?00011? or ?00001? in the lower five bits will have no effect.
166 9137e?rke?12/10 atmel ATA5771/73/74 4.23 memory programming this section describes the different methods for programming the atmel ? attiny44v memories. 4.23.1 program and data memory lock bits the attiny44v provides two lock bits which can be left unprogrammed (?1?) or can be pro- grammed (?0?) to obtain the additional security listed in table 4-57 . the lock bits can only be erased to ?1? with the chip erase command. program memory can be read out via the debugwire interface when the dwen fuse is pro- grammed, even if the lock bits are set. thus, when lock bit security is required, should always debugwire be disabled by clearing the dwen fuse. note: 1. ?1? means unprogrammed, ?0? means programmed notes: 1. program the fuse bits before programming the lb1 and lb2. 2. ?1? means unprogrammed, ?0? means programmed table 4-56. lock bit byte (1) lock bit byte bit no de scription default value 7 ? 1 (unprogrammed) 6 ? 1 (unprogrammed) 5 ? 1 (unprogrammed) 4 ? 1 (unprogrammed) 3 ? 1 (unprogrammed) 2 ? 1 (unprogrammed) lb2 1 lock bit 1 (unprogrammed) lb1 0 lock bit 1 (unprogrammed) table 4-57. lock bit protection modes (1)(2) memory lock bits protection type lb mode lb2 lb1 1 1 1 no memory lock features enabled. 210 further programming of the flash and eeprom is disabled in high-voltage and serial programming mode. the fuse bits are locked in both serial and high-voltage programming mode. (1) debugwire is disabled. 300 further programming and verification of the flash and eeprom is disabled in high-voltage and serial programming mode. the fuse bits are locked in both serial and high-voltage programming mode. (1) debugwire is disabled.
167 9137e?rke?12/10 atmel ATA5771/73/74 4.23.2 fuse bytes the atmel ? attiny44v has three fuse bytes. table 4-59 to table 4-60 on page 168 describe briefly the functionality of all the fuses and how they are mapped into the fuse bytes. note that the fuses are read as logical zero, ?0?, if they are programmed. notes: 1. see section 4.14.3.2 ?alternate func tions of port b? on page 72 for description of rst- disbl and dwen fuses. when programming the rstdisbl fuse, high-voltage serial programming has to be used to change fuses to perform further programming 2. dwen must be unprogrammed when lock bit security is required. see section 4.23.1 ?pro- gram and data memory lock bits? on page 166 . 3. the spien fuse is not accessible in spi programming mode. 4. see table 4-16 on page 50 for details. 5. see table 8-4 on page 190 for bodlevel fuse decoding. table 4-58. fuse extended byte fuse high byte bit no description default value 7 - 1 (unprogrammed) 6 - 1 (unprogrammed) 5 - 1 (unprogrammed) 4 - 1 (unprogrammed) 3 - 1 (unprogrammed) 2 - 1 (unprogrammed) 1 - 1 (unprogrammed) selfprgen 0 self-programming enable 1 (unprogrammed) table 4-59. fuse high byte fuse high byte bit no desc ription default value rstdisbl (1) 7 external reset disable 1 (unprogrammed) dwen (2) 6 debugwire enable 1 (unprogrammed) spien (3) 6 enable serial program and data downloading 0 (programmed, spi prog. enabled) wdton (4) 4 watchdog timer always on 1 (unprogrammed) eesave 3 eeprom memory is preserved through the chip erase 1 (unprogrammed, eeprom not preserved) bodlevel2 (5) 2 brown-out detector trigger level 1 (unprogrammed) bodlevel1 (5) 1 brown-out detector trigger level 1 (unprogrammed) bodlevel0 (5) 0 brown-out detector trigger level 1 (unprogrammed)
168 9137e?rke?12/10 atmel ATA5771/73/74 notes: 1. see section 4.9.9 ?system clock prescaler? on page 38 for details. 2. the default value of sut1..0 results in maximum start-up time for the default clock source. see table 4-9 on page 36 for details. 3. the default setting of ckse l3..0 results in internal rc oscillator @ 8.0 mhz. see table 4-8 on page 36 for details. the status of the fuse bits is not affected by chip erase. note that the fuse bits are locked if lock bit1 (lb1) is programmed. program the fuse bits before programming the lock bits. 4.23.2.1 latching of fuses the fuse values are latched when the device enters programming mode and changes of the fuse values will have no effect until the part leaves programmin g mode. this does not apply to the eesave fuse which will take effect once it is programmed. the fuse s are also latched on power-up in normal mode. 4.23.3 signature bytes all atmel ? microcontrollers have a three-byte sig nature code which identifies the device. this code can be read in both serial and high-voltage programming mode, also when the device is locked. the three bytes reside in a separate addr ess space. for the attiny44v the signature bytes are given in table 4-61 . 4.23.4 calibration byte signature area of the attiny44v has one byte of calibration data for the internal rc oscillator. this byte resides in the high byte of address 0x000. during reset, this byte is automatically written into the osccal regist er to ensure correct frequency of the calibrated rc oscillator. table 4-60. fuse low byte fuse low byte bit no description default value ckdiv8 (1) 7 divide clock by 8 0 (programmed) ckout 6 clock output enable 1 (unprogrammed) sut1 5 select start-up time 1 (unprogrammed) (2 sut0 4 select start-up time 0 (programmed) (2 cksel3 3 select clock source 0 (programmed) (3) cksel2 2 select clock source 0 (programmed) (3) cksel1 1 select clock source 1 (unprogrammed) (3) cksel0 0 select clock source 0 (programmed) (3) table 4-61. device id atmel parts signature bytes address 0x000 0x001 0x002 attiny44v 0x1e 0x92 0x07
169 9137e?rke?12/10 atmel ATA5771/73/74 4.23.5 page size 4.23.6 serial downloading both the flash and eeprom memory arrays can be programmed using the serial spi bus while reset is pulled to gnd. the serial interface consists of pins sck, mosi (input) and miso (output). after reset is set low, the programming enable instruction needs to be exe- cuted first before program/erase operations can be executed. note, in table 4-64 , the pin mapping for spi programming is listed. not all parts use the spi pins dedicated for the internal spi interface. figure 4-73. serial programming and verify (1) note: 1. if the device is clocked by the internal oscillator, it is no need to connect a clock source to the clki pin. table 4-62. no. of words in a page and no. of pages in the flash atmel device flash size page size pcword no. of pages pcpage pcmsb attiny44v 4k bytes 32 words pc[4:0] 64 pc[10:5] 10 table 4-63. no. of words in a page and no. of pages in the eeprom atmel device eeprom size page size pcword no. of pages pcpage eeamsb attiny44v 256 bytes 4 bytes eea[1:0] 64 eea[7:2] 7 table 4-64. pin mapping serial programming symbol pins i/o description mosi pa6 i serial data in miso pa5 o serial data out sck pa4 i serial clock vcc gnd sck miso mosi reset +1.8 - 5.5v
170 9137e?rke?12/10 atmel ATA5771/73/74 when programming the eeprom, an auto-erase cycl e is built into the self-timed program- ming operation (in the serial mode only) and there is no need to first execute the chip erase instruction. the chip erase operation turns the content of every memory location in both the program and eeprom arrays into 0xff. depending on cksel fuses, a valid clock must be present. th e minimum low a nd high peri- ods for the serial clock (sck) input are defined as follows: low: > 2 cpu clock cycles for f ck < 12 mhz, 3 cpu clock cycles for f ck >= 12mhz high: > 2 cpu clock cycles for f ck < 12 mhz, 3 cpu clock cycles for f ck >= 12mhz 4.23.6.1 serial programming algorithm when writing serial data to the atmel ? attiny44v, data is clocked on the rising edge of sck. when reading data from the attiny44v, data is clocked on the falling edge of sck. see figure 8-3 on page 193 and figure 8-4 on page 193 for timing details. to program and verify the attiny44v in the serial programming mode, the following sequence is recommended (see four byte instruction formats in table 4-66 on page 172 ): 1. power-up sequence: apply power between v cc and gnd while reset and sck are set to ?0?. in some sys- tems, the programmer can not guarantee that sck is held low during power-up. in this case, reset must be given a positive pulse of at least two cpu clock cycles duration after sck has been set to ?0?. 2. wait for at least 20 ms and enable serial programming by sending the programming enable serial instruction to pin mosi. 3. the serial programming instructions will no t work if the communic ation is out of syn- chronization. when in sync. the second byte (0x53), will echo back when issuing the third byte of the programming enable instruction. whether the echo is correct or not, all four bytes of the instruction must be transmitted. if the 0x53 did not echo back, give reset a positive pulse and issue a new programming enable command. 4. the flash is programmed one page at a time. the memory page is loaded one byte at a time by supplying the 5 lsb of the address and data together with the load program memory page instruction. to ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. the program memory page is stored by loading the write program memory page instruction with the 3 msb of the address . if polling (rdy/bsy) is not used, the user must wait at least t wd_flash before issuing the next page. (see table 4-65 on page 171 .) accessing the serial programming interface before the flash write operation completes can result in incorrect programming.
171 9137e?rke?12/10 atmel ATA5771/73/74 5. a: the eeprom array is programmed one byte at a time by supply ing the ad dress and data together with the appropriate write instruction. an eeprom memory location is first automatically erased before new data is written. if polling (rdy/bsy) is not used, the user must wait at least t wd_eeprom before issuing the next byte. (see table 4-65 on page 171 .) in a chip erased device, no 0xffs in the data file(s) need to be pro- grammed. b: the eeprom array is programmed one page at a time. the memory page is loaded one byte at a time by supplying the 2 lsb of the address and data together with the load eeprom memory pa ge instruction. the eeprom memory page is stored by loading the write eeprom memory pa ge instruction with the 4 msb of the address. when using eeprom page access on ly byte locations lo aded with the load eeprom memory page instruction is alte red. the remaining locations remain unchanged. if polling (rdy/bsy) is not used, the used must wait at least t wd_eeprom before issuing the next page (see table 4-65 on page 171 ). in a chip erased device, no 0xff in the data file(s) need to be programmed. 6. any memory location can be verified by using the read instruction which returns the content at the selected address at serial output miso. 7. at the end of the programming session, reset can be set high to commence normal operation. 8. power-off sequence (if needed): set reset to ?1?. tu r n v cc power off. table 4-65. minimum wait delay before writing the next flash or eeprom location symbol minimum wait delay t wd_flash 4.5 ms t wd_eeprom 4.0 ms t wd_erase 4.0 ms t wd_fuse 4.5 ms
172 9137e?rke?12/10 atmel ATA5771/73/74 4.23.6.2 serial programming instruction set table 4-66 and figure 4-74 on page 173 describes the instruction set. notes: 1. not all instructions are applicable for all parts. 2. a = address 3. bits are programmed ?0?, unprogrammed ?1?. 4. to ensure future compatibility, unused fuses and lock bits should be unprogrammed (?1?) . 5. refer to the correspondig section for fuse and lock bits, calibration and signature bytes and page size. 6. instructions accessing program memory use a word address. this address may be random within the page range. 7. see htt://www.atmel.com/avr for application notes regarding programming and programmers. table 4-66. serial programming instruction set instruction/operation (1) instruction format byte 1 byte 2 byte 3 byte4 programming enable $ac $53 $00 $00 chip erase (program memory/eeprom) $ac $80 $00 $00 poll rdy/bsy $f0 $00 $00 data byte out load instructions load extended address byte $4d $00 extended adr $00 load program memory page, high byte $48 adr msb adr lsb high data byte in load program memory page, low byte $40 adr msb adr lsb low data byte in load eeprom memory page (page access) $c1 $00 adr lsb data byte in read instructions read program memory, high byte $28 adr msb adr lsb high data byte out read program memory, low byte $20 adr msb adr lsb low data byte out read eeprom memory $a0 $00 adr lsb data byte out read lock bits $58 $00 $00 data byte out read signature byte $30 $00 adr lsb data byte out read fuse bits $50 $00 $00 data byte out read fuse high bits $58 $08 $00 data byte out read extended fuse bits $50 $08 $00 data byte out read calibration byte $38 $00 $00 data byte out write instructions (6) write program memory page $4c adr msb adr lsb $00 write eeprom memory $c0 $00 adr lsb data byte in write eeprom memory page (page access) $c2 $00 adr lsb $00 write lock bits $ac $e0 $00 data byte in write fuse bits $ac $a0 $00 data byte in write fuse high bits $ac $a8 $00 data byte in write extended fuse bits $ac $a4 $00 data byte in
173 9137e?rke?12/10 atmel ATA5771/73/74 if the lsb in rdy/bsy data byte out is ?1?, a program ming operation is still pending. wait until this bit returns ?0? before the ne xt instruction is carried out. within the same page, the low data byte must be loaded prior to the high data byte. after data is lo aded to the page buffer, pr ogram the eeprom page, see figure 4-74 on page 173 . figure 4-74. serial programming instruction example byte 1 byte 2 byte 3 byte 4 adr lsb bit 15 b 0 serial programming instruction program memory/ eeprom memory page 0 page 1 page 2 page n-1 page buffer write program memory page/ write eeprom memory page load program memory page (high/low byte)/ load eeprom memory page (page access) byte 1 byte 2 byte 3 byte 4 bit 15 b 0 adr msb page offset page number ad r m ms sb a a adr r l lsb b
174 9137e?rke?12/10 atmel ATA5771/73/74 4.23.7 high-voltage serial programming this section describes how to program and verify flash program memory, eeprom data memory, lock bits and fuse bits in the atmel ? attiny44v. figure 4-75. high-voltage serial programming the minimum period for the serial clock input (sci) during high-voltage serial programming is 220 ns. table 4-67. pin name mapping signal name in high-voltage serial programming mode pin name i/o function sdi pa6 i serial data input sii pa5 i serial instruction input sdo pa4 o serial data output sci pb0 i serial clock input (min. 220ns period) table 4-68. pin values used to enter programming mode pin symbol value pa0 prog_enable[0] 0 pa1 prog_enable[1] 0 pa2 prog_enable[2] 0 vcc gnd sdo sii sdi (reset) +1.8 - 5.5v pa6 pa5 pa4 pb3 +11.5 - 12.5v pb0 sci
175 9137e?rke?12/10 atmel ATA5771/73/74 4.23.8 high-voltage serial programming algorithm to program and verify the atmel ? attiny44v in the high-voltage serial programming mode, the following sequence is recommended (see instruction formats in table 4-70 on page 178 ): 4.23.8.1 enter high-voltage serial programming mode the following algorithm puts the device in high-voltage serial programming mode: 1. apply 4.5 - 5.5v between v cc and gnd. 2. set reset pin to ?0? and to ggle sci at least six times. 3. set the prog_enable pins listed in table 4-68 on page 174 to ?000? and wait at least 100 ns. 4. apply v hvrst - 5.5v to reset. keep the prog_enable pins unchanged for at least t hvrst after the high-voltage has been applied to ensure the prog_enable signature has been latched. 5. shortly after latching the pr og_enable signat ure, the device will activly output data on the prog_enable[2]/sdo pin, and the resulting drive contention may increase the power consumption. to minimize this drive contention, release the prog_enable[2] pin after t hvrst has elapsed. 6. wait at least 50 s before giving any serial instructions on sdi/sii. 4.23.8.2 considerations for efficient programming the loaded command and address are retained in the device during programming. for effi- cient programming, the following should be considered. ? the command needs only be loaded once when writing or reading multiple memory locations. ? skip writing the data value 0xff that is the contents of the entire eeprom (unless the eesave fuse is programmed) and flash after a chip erase. ? address high byte needs only be loaded before programming or reading a new 256 word window in flash or 256 byte eeprom. this consideration also applies to signature bytes reading. 4.23.8.3 chip erase the chip erase will erase the flash and eeprom (1) memories plus lock bits. the lock bits are not reset until the program memory has been completely erased. the fuse bits are not changed. a chip erase must be performe d before the flash and/or eeprom are re-programmed. note: 1. the eeprom memory is preserved during chip erase if the eesave fuse is programmed. 1. load command ?chip erase? (see table 4-70 on page 178 ). 2. wait after instr. 3 until sdo goes high for the ?chip erase? cycle to finish. 3. load command ?no operation?. table 4-69. high-voltage reset characteristics supply voltage reset pin high-voltage threshold minimum high-voltage period for latching prog_enable v cc v hvrst t hvrst 4.5v 11.5v 100 ns 5.5v 11.5v 100 ns
176 9137e?rke?12/10 atmel ATA5771/73/74 4.23.8.4 programming the flash the flash is organized in pages, see section 4.23.5 ?page size? on page 169 . when pro- gramming the flash, the program data is latched into a page buffer. this allows one page of program data to be programmed simultaneously. the following procedure describes how to program the entire flash memory: 1. load command ?write flash? (see table 4-70 on page 178 ). 2. load flash page buffer. 3. load flash high address and program page. wait after instr. 3 until sdo goes high for the ?page programming? cycle to finish. 4. repeat 2 through 3 until the entire flash is programmed or until all data has been programmed. 5. end page programming by loading command ?no operation?. when writing or reading serial data to the attiny44v, data is clocked on the rising edge of the serial clock, see figure 8-5 on page 194 , figure 4-75 on page 174 and table 8-8 on page 194 for details. figure 4-76. addressing the flash which is organized in pages figure 4-77. high-voltage serial programming waveforms program memory word address within a page page address within the flash instruction word pag e pcword[pagemsb:0]: 00 01 02 pageend pag e pcword pcpage pcmsb pagemsb program counter msb msb msb lsb lsb lsb 012345678910 sdi pb0 sii pb1 sdo pb2 sci pb3
177 9137e?rke?12/10 atmel ATA5771/73/74 4.23.8.5 programming the eeprom the eeprom is organi zed in pages, see table 8-7 on page 193 . when programming the eeprom, the data is latched into a page buffer. this allows one page of data to be pro- grammed simultaneously. the programming algorithm for the eeprom data memory is as follows (refer to table 4-70 on page 178 ): 1. load command ?write eeprom?. 2. load eeprom page buffer. 3. program eeprom page. wait after instr. 2 until sdo goes high for the ?page pro- gramming? cycle to finish. 4. repeat 2 through 3 until the entire eeprom is progra mmed or until all data has been programmed. 5. end page programming by loading command ?no operation?. 4.23.8.6 reading the flash the algorithm for reading the flash memory is as follows (refer to table 4-70 on page 178 ): 1. load command "read flash". 2. read flash low and high bytes. the contents at the selected address are available at serial output sdo. 4.23.8.7 reading the eeprom the algorithm for reading the eeprom memory is as follows (refer to table 4-70 on page 178 ): 1. load command ?read eeprom?. 2. read eeprom byte. the contents at the selected address are available at serial out- put sdo. 4.23.8.8 programming and reading the fuse and lock bits the algorithms for programming and reading the fuse low/high bits and lock bits are shown in table 4-70 on page 178 . 4.23.8.9 reading the signature bytes and calibration byte the algorithms for reading the signature bytes and calibration byte are shown in table 4-70 on page 178 . 4.23.8.10 power-off sequence set sci to ?0?. set reset to ?1?. turn v cc power off.
178 9137e?rke?12/10 atmel ATA5771/73/74 table 4-70. high-voltage serial programming instruction set for atmel ? attiny44v instruction instruction format operation remarks instr.1/5 instr.2/6 instr.3/7 instr.4 chip erase sdi sii sdo 0_1000_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr.3 until sdo goes high for the chip erase cycle to finish. load ?write flash? command sdi sii sdo 0_0001_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx enter flash programming code. load flash page buffer sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ eeee _ eeee _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1101_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx repeat after instr. 1 - 7until the entire page buffer is filled or until all data within the page is filled. see note 1. sdi sii sdo 0_ dddd _ dddd _00 0_0011_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1101_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 x_xxxx_xxxx_xx instr 5-7. load flash high address and program page sdi sii sdo 0_0000_000 a _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr 3 until sdo goes high. repeat instr. 2 - 3 for each loaded flash page until the entire flash or all data is programmed. repeat instr. 1 for a new 256 byte page. see note 1. load ?read flash? command sdi sii sdo 0_0000_0010_00 0_0100_1100_00 x_xxxx_xxxx_xx enter flash read mode. read flash low and high bytes sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_0000_000 a _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 q _ qqqq _ qqq x_xx repeat instr. 1, 3 - 6 for each new address. repeat instr. 2 for a new 256 byte page. sdi sii sdo 0_0000_0000_00 0_0111_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 p _ pppp _ ppp x_xx instr 5 - 6. load ?write eeprom? command sdi sii sdo 0_0001_0001_00 0_0100_1100_00 x_xxxx_xxxx_xx enter eeprom programming mode. load eeprom page buffer sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ aaaa _ aaaa _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_ eeee _ eeee _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1101_00 x_xxxx_xxxx_xx repeat instr. 1 - 5 until the entire page buffer is filled or until all data within the page is filled. see note 2. sdi sii sdo 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx note: a = address high bits, b = address low bits, d = data in high bits, e = data in low bits, p = data out high bits, q = data out low bits, x = don?t care, 1 = lock bit1, 2 = lock bit2, 3 = cksel0 fuse, 4 = cksel1 fuse, 5 = cksel2 fuse, 6 = cksel3 fuse, 7 = sut0 fuse, 8 = sut1 fuse, 9 = ckdiv8 fuse, a = ckout fuse, b = bodlevel0 fuse, c = bodlevel1 fuse, d = bodlevel2 fuse, e = eesave fuse, f = wdton fuse, g = spien fuse, h = dwen fuse, i = rstdisbl fuse notes: 1. for page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address. 2. for page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address. 3. the eeprom is written page-wise. but only the bytes that are loaded into the page are ac tually written to the eeprom. page-wise eeprom access is more efficient when multiple bytes are to be written to the same page. note that auto-erase of eeprom is not available in high-voltage serial programming, only in spi programming.
179 9137e?rke?12/10 atmel ATA5771/73/74 program eeprom page sdi sii sdo 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr. 2 until sdo goes high. repeat instr. 1 - 2 for each loaded eeprom page until the entire eeprom or all data is programmed. write eeprom byte sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ aaaa _ aaaa _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_ eeee _ eeee _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1101_00 x_xxxx_xxxx_xx repeat instr. 1 - 6 for each new address. wait after instr. 6 until sdo goes high. see note 3. sdi sii sdo 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx instr. 5-6 load ?read eeprom? command sdi sii sdo 0_0000_0011_00 0_0100_1100_00 x_xxxx_xxxx_xx enter eeprom read mode. read eeprom byte sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ aaaa _ aaaa _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 q _ qqqq _ qqq 0_00 repeat instr. 1, 3 - 4 for each new address. repeat instr. 2 for a new 256 byte page. write fuse low bits sdi sii sdo 0_0100_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_ a987 _ 6543 _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write a - 3 = ?0? to program the fuse bit. write fuse high bits sdi sii sdo 0_0100_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_ ihgf _ edcb _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write f - b = ?0? to program the fuse bit. write fuse extended bits sdi sii sdo 0_0100_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_000 j _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0110_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1110_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write j = ?0? to program the fuse bit. write lock bits sdi sii sdo 0_0010_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_00 21 _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write 2 - 1 = ?0? to program the lock bit. read fuse low bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 a _ 9876 _ 543 x_xx reading a - 3 = ?0? means the fuse bit is programmed. read fuse high bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1010_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 i _ hgfe _ dcb x_xx reading f - b = ?0? means the fuse bit is programmed. read fuse extended bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1010_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1110_00 x_xxxx_xxjx_xx reading j = ?0? means the fuse bit is programmed. table 4-70. high-voltage serial programming instruction set for atmel ? attiny44v (continued) instruction instruction format operation remarks instr.1/5 instr.2/6 instr.3/7 instr.4 note: a = address high bits, b = address low bits, d = data in high bits, e = data in low bits, p = data out high bits, q = data out low bits, x = don?t care, 1 = lock bit1, 2 = lock bit2, 3 = cksel0 fuse, 4 = cksel1 fuse, 5 = cksel2 fuse, 6 = cksel3 fuse, 7 = sut0 fuse, 8 = sut1 fuse, 9 = ckdiv8 fuse, a = ckout fuse, b = bodlevel0 fuse, c = bodlevel1 fuse, d = bodlevel2 fuse, e = eesave fuse, f = wdton fuse, g = spien fuse, h = dwen fuse, i = rstdisbl fuse notes: 1. for page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address. 2. for page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address. 3. the eeprom is written page-wise. but only the bytes that are loaded into the page are ac tually written to the eeprom. page-wise eeprom access is more efficient when multiple bytes are to be written to the same page. note that auto-erase of eeprom is not available in high-voltage serial programming, only in spi programming.
180 9137e?rke?12/10 atmel ATA5771/73/74 read lock bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_x 21 x_xx reading 2, 1 = ?0? means the lock bit is programmed. read signature bytes sdi sii sdo 0_0000_1000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_00 bb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 q _ qqqq _ qqq x_xx repeats instr 2 4 for each signature byte address. read calibration byte sdi sii sdo 0_0000_1000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0000_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 p _ pppp _ ppp x_xx load ?no operation? command sdi sii sdo 0_0000_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx table 4-70. high-voltage serial programming instruction set for atmel ? attiny44v (continued) instruction instruction format operation remarks instr.1/5 instr.2/6 instr.3/7 instr.4 note: a = address high bits, b = address low bits, d = data in high bits, e = data in low bits, p = data out high bits, q = data out low bits, x = don?t care, 1 = lock bit1, 2 = lock bit2, 3 = cksel0 fuse, 4 = cksel1 fuse, 5 = cksel2 fuse, 6 = cksel3 fuse, 7 = sut0 fuse, 8 = sut1 fuse, 9 = ckdiv8 fuse, a = ckout fuse, b = bodlevel0 fuse, c = bodlevel1 fuse, d = bodlevel2 fuse, e = eesave fuse, f = wdton fuse, g = spien fuse, h = dwen fuse, i = rstdisbl fuse notes: 1. for page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address. 2. for page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address. 3. the eeprom is written page-wise. but only the bytes that are loaded into the page are ac tually written to the eeprom. page-wise eeprom access is more efficient when multiple bytes are to be written to the same page. note that auto-erase of eeprom is not available in high-voltage serial programming, only in spi programming.
181 9137e?rke?12/10 atmel ATA5771/73/74 5. application figure 5-1 illustrates a principle application circui t using loop antenna. for the blocking mea- sure of the power supply voltage, a capacitor value of c 3 = 68 nf/x7r is recommended. c 1 and c 2 are used to match the loop antenna to the pow er amplifier. two capacitors in series should be used to achieve a better tolerance value for c 2 and allowing the po ssibility of realiz- ing the z load,opt using standard valued capacitors. figure 5-1. the principle application circuit usin g a loop antenna for ask modulation together with the pins and the pcb board wires c 1 forms a series resonance loop that sup- press the 1 st harmonic. therefore the position of c 1 on the pcb is important. generally the best suppression is achieved when c 1 is placed as close as possible to the pins ant1 and ant2. the loop antenna should not exceed a width of 1.5 mm, otherwise the q-factor of the loop antenna is too high. the capacitor c 4 should be selected that the xto runs on the load resonance frequency of the crystal. ATA5771/7 3 /74 vco pll xto f/4 power u p / down enable pxy gnd vdd v s gnd_rf vcc_rf clk pa pxy v s pa_enable ant2 ant1 v s loop antenn a pxy pxy s 1 pxy s 1 pxy s 1 pxy pxy pxy pxy pxy pxy c 3 c1 c2 c4
182 9137e?rke?12/10 atmel ATA5771/73/74 figure 5-2. typical ask application atmel ? ata577x pb0/xtal1 vdd pb 3 /re s et pb2 pa 7 adc7 gnd_rf gnd xtal vcc_rf enable gnd pa_enable gnd ant1 ant2 clk pa 6 adc6 pb1/xtal2 pa1/adc1 pa0/adc0 2 3 pa 3 /adc 3 pa4/adc4 pa5/adc5 pa2/adc2 c5 vcc vcc vcc l1 ata577x s w1 s w 3 s w2 c 8 q1 c6 r 3 c7 r2 c4 c 3 c2 l2 c1 r1 table 5-1. bill of material component value type/ manufacturer note 315 mhz 433.92mhz 868.3mhz l1 100nh 82nh 22nh ll1608-fsl/ toko l2 39nh 27nh 2.2nh ll1608-fsl/ toko c1 1nf 1nf 1nf grm1885c/ murata c2 3.9pf 2.7pf 1.5pf grm1885c/ murata this cap must be placed as close as possible to the pin ant1 and ant2 c3 27pf 16pf 4.3pf grm1885c/ murata on the demo board 2 capacitors in series are used to reduce the tolerance c4 3.9pf 1.6pf 0.3pf grm1885c/ murata on the demo board 2 capacitors in series are used to reduce the tolerance c5 68nf 68nf 68nf grm188r71c/ murata this cap must placed as close as possible to the vcc_rf
183 9137e?rke?12/10 atmel ATA5771/73/74 figure 5-3. typical fsk application atmel ? ata577x note: fsk modulation is achieved by switching on and off an additional capacitor between the xtal load capacitor and gnd. this is done using a mos switch controlled by a microcontroller output. c6 100nf 100nf 100nf grm188r71c / murata this cap must placed as close as possible to the vdd c7 100nf 100nf 100nf grm188r71c / murata c8 10pf 12pf 12pf grm1885c/ murata q1 9.843750mhz 13.56mhz 13.567187mhz dsx530gk/ kds r1 100k 100k 100k r2 100k 100k 100k r3 10k 10k 10k table 5-1. bill of material (continued) component value type/ manufacturer note pb0/xtal1 vdd pb 3 /re s et pb2 pa 7 adc7 gnd_rf gnd xtal vcc_rf enable gnd pa_enable gnd ant1 ant2 clk pa 6 adc6 pb1/xtal2 pa1/adc1 pa0/adc0 pa 3 /adc 3 pa4/adc4 pa5/adc5 pa2/adc2 c5 vcc vcc vcc ata577x s w1 s w 3 s w2 t1 c9 q1 c 8 c6 c7 r 3 r2 r1 c4 c 3 c2 l1 l2 c1
184 9137e?rke?12/10 atmel ATA5771/73/74 table 5-2. bill of material component value type/ manufacturer note 315mhz 433.92mhz 868.3mhz l1 100nh 82nh 22nh ll1608-fsl/ toko l2 39nh 27nh 2.2nh ll1608-fsl/ toko c1 1nf 1nf 1nf grm1885c/ murata c2 3.9pf 2.7pf 1.5pf grm1885c/ murata this cap must be placed as close as possible to the pin ant1 and ant2 c3 27pf 16pf 4.3pf grm1885c/ murata on the demo board 2 capacitors in series are used to reduce the tolerance c4 3.9pf 1.6pf 0.3pf grm1885c/ murata on the demo board 2 capacitors in series are used to reduce the tolerance c5 68nf 68nf 68nf grm188r71c/ murata this cap must placed as close as possible to the vcc_rf c6 100nf 100nf 100nf grm188r71c / murata this cap must placed as close as possible to the vdd c7 100nf 100nf 100nf grm188r71c / murata c8 3.9pf 4.7pf 5.6pf grm1885c/ murata frequency deviation of 16 khz will be performed using the combination of c8 and c9 c9 18pf 8.2pf 5.6pf grm1885c/ murata frequency deviation of 16 khz will be performed using the combination of c8 and c9 t1 bss83 q1 9.843750mhz 13.56mhz 13.567187mhz dsx530gk/ kds r1 100k 100k 100k r2 100k 100k 100k r3 10k 10k 10k
185 9137e?rke?12/10 atmel ATA5771/73/74 6. absolute maximum ratings figure 6-1. esd protection circuit of the transmitter notes: 1. maximum current per port = 30ma 2. functional corruption may occur. 6.1 rf transmitter block stresses beyond those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at these or any other conditions beyond t hose indicated in the operational sections of this specification is not implied. exposure to absolute maximum rati ng conditions for extended periods may affect device reliability . parameters symbol minimum maximum unit supply voltage v s 5v power dissipation p tot 100 mw junction temperature t j 150 c storage temperature t stg ?55 +125 c ambient temperature t amb ?55 +125 c input voltage v maxpa_enable ?0.3 (v s + 0.3) (1) v note: 1. if v s + 0.3 is higher than 3.7v, the maximum voltage will be reduced to 3.7v clk vs gnd pa_enable xtal ant2 enable ant1 6.2 microcontroller block (atmel attiny44v) operating temperature ................................... ?40c to + 85c note: stresses beyond those lis ted under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. storage temperature... .............. .............. ...... ?65c to +175c voltage on any pin except reset with respect to ground ............................... ?0.5v to v cc +0.5v maximum operating voltage .............................................6.0v voltage on reset with respect to ground .... ?0.5v to +13.0v voltage on v cc with respect to ground ............ ?0.5v to +6.0v dc current per i/o pin .................................................30.0ma dc current v cc and gnd pins ..................................200.0ma injection current at v cc = 0v to 5v (2) ........................5.0ma (1)
186 9137e?rke?12/10 atmel ATA5771/73/74 8. electrical characteristics note: these values are based on the dc electrical values in section 8.2 ?rf transmitter block? on page 186 and section 8.3 ?micro- controller block? on page 188 . 7. thermal resistance parameters symbol value unit junction ambient r thja 35 k/w 8.1 the general current c onsumption characteristic for key fob application v s = 2.0v to 3.6v, t amb = ?40c to +85c unless otherwise specified. typical values are given at v s = 3.0v and t amb = 25c. transmitter (t5750/3/4) attiny44v wdt disabled total power down typ. < 10na typ. 2.5a typ. < 2.51a max. 350na max. 3a max. 3.35a active (v s =3v; rc = 4mhz) 315mhz / 434mhz typ. 9ma typ. 0.8ma typ. 9.8ma max. 11.6ma max. 2.5ma max. 14.1ma 868mhz typ. 8.5ma typ. 0.8ma typ. 9.3ma max. 11ma max. 2.5ma max. 13.5ma 8.2 rf transmitter block v s = 2.0v to 3.6v, t amb = ?40c to +85c unless otherwise specified. typical values are given at v s = 3.0v and t amb = 25c. all parameters are referred to gnd (pin 7) parameters test conditions symbol min. typ. max. unit supply current of rf transmitter block (* please take account an additional current consumption of the microcontroller block) power down, v enable < 0.25 v, ?40c to +85c v pa-enable < 0.25v, 25c i s_off < 10 350 na na power up, pa off, v s = 3v, v enable > 1.7v, v pa-enable < 0.25v 315 mhz / 434 mhz 868 mhz is 3.7 3.6 4.8 4.6 ma power up, v s = 3.0v, v enable > 1.7v, v pa-enable > 1.7v 315 mhz / 434 mhz 868 mhz i s_transmit 9 8.5 11.6 11 ma output power v s =3.0v, t amb =25c, f = 315 mhz, z load = (255 + j192) f = 433.92 mhz, z load = (166 + j233) f = 868.3 mhz, z load = (166 + j226) p ref 6.0 5.5 3.5 8.0 7.5 5.5 10.5 10 8 dbm output power variation for the full temperature range t amb = ?40c to +85c, v s = 3.0v v s = 2.0v p out = p ref + p ref p ref p ref ?1.5 ?4.0 db db note: 1. if v s is higher than 3.6v, the maximum voltage will be reduced to 3.6v.
187 9137e?rke?12/10 atmel ATA5771/73/74 achievable output-power range selectable by load impedance 315mhz 434mhz 868mhz p out_typ 0 0 ?3 8.0 7.5 +5.5 dbm spurious emission f clk = f 0 /128 (ata5773 / ata5774) f clk = f 0 /256 (ATA5771) load capacitance at pin clk = 10 pf f o 1 f clk (ata5773 / ata5774) f o 1 f clk (ATA5771) f o 4 f clk other spurious are lower ?55 ?52 ?52 dbc dbc dbc oscillator frequency xto (= phase comparator frequency) f xto = f 0 /32 (ata5773 / ata5774) f xto = f 0 /64 (ATA5771) f xtal = resonant frequency of the xtal, c m 10 ff, load capacitance selected accordingly t amb = ?40c to +85c f xto ?30 f xtal +30 ppm pll loop bandwidth 250 khz phase noise of phase comparator referred to f pc = f xt0, 25khz distance to carrier ?116 ?110 dbc/hz in-loop phase noise pll 25khz distance to carrier ?86 ?80 dbc/hz phase noise vco at 1mhz at 36mhz ?94 ?125 ?90 ?121 dbc/hz dbc/hz frequency range of vco ata 5 7 7 3 ata 5 7 7 4 ata 5 7 7 1 f vco 310 429 868 350 439 928 mhz clock output frequency (cmos microcontroller compatible) ata5773 / ata5774 ata 5 7 7 1 f 0 /128 f 0 /256 mhz voltage swing at pin clk c load 10pf v 0h v 0l v s 0.8 v s 0.2 v v series resonance r of the crystal rs 110 capacitive load at pin xt0 7pf fsk modulation frequency rate duty cycle of the modulation si gnal = 50% 0 32 khz ask modulation frequency rate duty cycle of the modulation si gnal = 50% 0 32 khz enable input low level input voltage high level input voltage input current high v il v ih i in 1.7 0.25 20 v v a pa_enable input low level input voltage high level input voltage input current high v il v ih i in 1.7 0.25 v s (1) 5 v v a 8.2 rf transmitter block (continued) v s = 2.0v to 3.6v, t amb = ?40c to +85c unless otherwise specified. typical values are given at v s = 3.0v and t amb = 25c. all parameters are referred to gnd (pin 7) parameters test conditions symbol min. typ. max. unit note: 1. if v s is higher than 3.6v, the maximum voltage will be reduced to 3.6v.
188 9137e?rke?12/10 atmel ATA5771/73/74 8.3 microcontroller block 8.3.1 dc characteristics t a = ?40c to +85c, v cc = 2.0v to 3.6v ( unless otherwise noted) (1) symbol parameter condition min. typ. max. unit v il input low voltage except xtal1 and reset pin v cc = 1.8v to 3.6v t a = ?40c to +85c ?0.5 +0.2v cc (1) v v il1 input low voltage, xtal1 pin v cc = 1.8v to 3.6v t a = ?40c to +85c ?0.5 +0.2v cc (1) v v ih input high voltage, except xtal1 and reset pins v cc = 1.8v to 3.6v t a = ?40c to +85c 0.7v cc (1) v cc + 0.5 v v ih1 input high voltage, xtal1 pin v cc = 1.8v to 3.6v t a = ?40c to +85c 0.9v cc (1) v cc + 0.5 v v il2 input low voltage, reset pin v cc = 1.8v to 3.6v t a = ?40c to +85c ?0.5 +0.2v cc (1) v v ih2 input high voltage, reset pin v cc = 1.8v to 3.6v t a = ?40c to +85c 0.9v cc (1) v cc + 0.5 v v ol output low voltage (2) , i/o pin except reset i ol = 2ma, v cc = 1.8v 0.2 v v oh output high voltage (3) , i/o pin except reset i oh = ?2ma, v cc = 1.8v 1.2 v r rst reset pull-up resistor 30 60 k r pu i/o pin pull-up resistor 20 50 k i cc power supply current active 4mhz, v cc = 3v t a = ?40c to +85c 0.8 2.5 ma idle 4mhz, v cc = 3v t a = ?40c to +85c 0.2 0.5 ma power-down mode wdt enabled, v cc = 3v 4 18 a wdt disabled, v cc = 3v 0.2 3 a v acio analog comparator input offset voltage v cc = 2.7v v in = v cc /2 t a = ?40c to +85c <10 40 mv i aclk analog comparator input leakage current v cc = 2.7v v in = v cc /2 t a = ?40c to +85c v cc = 1.8v to 3.6v ?50 +50 na notes: 1. ?max? means the highest value where t he pin is guaranteed to be read as low. 2. ?min? means the lowest value where the pin is guaranteed to be read as high. 3. although each i/o port can sink more than the test conditions (10ma at v cc = 5v, 5ma at v cc = 3v) under steady state con- ditions (non-transient), the following must be observed: 1] the sum of all iol, for all ports, should not exceed 60ma. if iol exceeds the test condition, vol may exceed the related specification. pins are not guaranteed to sink current greater than the listed test condition. 4. although each i/o port can source more than the test conditions (10ma at v cc = 5v, 5ma at v cc = 3v) under steady state conditions (non-transient), the following must be observed: 1] the sum of all ioh, for all ports, should not exceed 60ma. if ioh exceeds the test condition, voh may exceed the related specification. pi ns are not guaranteed to source current greater than the listed test condition. pull up driv ing strenght of the pb3 reset pad is weak.
189 9137e?rke?12/10 atmel ATA5771/73/74 8.3.2 maximum speed versus v cc maximum frequency is dependent on v cc . as shown in figure 8-1 , the maximum frequency versus v cc curve is linear between 1.8v < v cc < 3.6v figure 8-1. maximum frequency versus v cc 8.3.3 clock characterizations 8.3.3.1 calibrate d internal rc oscillator accuracy 8.3.3.2 external clock drive waveforms figure 8-2. external clock drive waveforms 4 mhz 8 mhz 1. 8 v 2.7v 3 .6v sa fe oper a ting are a table 8-1. calibration accuracy of internal rc oscillator frequency v cc temperature accuracy user calibration 7.3mhz to 8.1mhz 1.8v to 3.6v ?40 c to +85 c25% v il1 v ih1
190 9137e?rke?12/10 atmel ATA5771/73/74 8.3.3.3 external clock drive 8.3.4 system and reset characterizations notes: 1. values are guidelines only. 2. this is the limit to which vdd ca n be lowered without losing ram data table 8-2. external clock drive symbol parameter v cc = 2.7 - 3.6v unit min. max. 1/t clcl clock frequency 0 10 mhz t clcl clock period 100 ns t chcx high time 40 ns t clcx low time 40 ns t clch rise time 1.6 s t chcl fall time 1.6 s t clcl change in period from one clock cycle to the next 2 % table 8-3. reset, brown-out and internal voltage reference characteristics (1) symbol parameter condition min typ max unit v hyst brown-out detector hysteresis 100 250 mv v ram (2) ram retention voltage (1) 50 mv t bod min pulse width on brown-out reset 2 ns v bg bandgap reference voltage v c c = 2.7v, t a = 25c 1.0 1.1 1.2 v t bg bandgap reference start-up time v c c = 2.7v, t a = 25c 40 70 s i bg bandgap reference current consumption v c c = 2.7v, t a = 25c 10 a table 8-4. bodlevel fuse coding (1) bodlevel min v bot typ v bot max v bot unit type* 111 bod disabled 110 1.7 1.8 2.0 v a 001 1.7 1.9 2.1 c 000 1.8 2.0 2.2 c 010 2.0 2.2 2.4 c 011 2.1 2.3 2.5 c 101 2.5 2.7 2.9 a *) type means: a = 100% tested, c = characterized on samples note: 1. v bot may be below nominal minimum operating voltage for some devices. for devices where this is the case, the device is tested down to v cc = v bot during the production test. this guarantees that a brown-out reset will occur before v cc drops to a voltage where correct operation of the microcontroller is no longer guaranteed
191 9137e?rke?12/10 atmel ATA5771/73/74 8.3.5 adc characteristics ? preliminary data table 8-5. adc characteristics, single ended channels. ?40c to +85c, unless otherwise noted symbol parameter condition min typ max unit resolution single ended conversion 10 bits tue absolute accuracy (including inl, dnl, quantization error, gain and offset error) v cc = 1.8v, v ref = 1.8v, adc clock = 200khz t a = ?40c to +85c 24.0lsb v cc = 1.8v, v ref = 1.8v, adc clock = 200khz noise reduction mode t a = ?40c to +85c 24.0lsb inl integral non-linearity (inl) v cc = 1.8v, v ref = 1.8v, adc clock = 200khz t a = ?40c to +85c 0.5 1.5 lsb dnl differential non-linearity (dnl) v cc = 1.8v, v ref = 1.8v, adc clock = 200khz t a = ?40c to +85c 0.2 0.7 lsb gain error v cc = 1.8v, v ref = 1.8v, adc clock = 200khz t a = ?40c to +85c ?7.0 ?3.0 +5.0 lsb offset error v cc = 1.8v, v ref = 1.8v, adc clock = 200khz t a = ?40c to +85c ?3.5 +1.5 +3.5 lsb conversion time free running conversion 65 260 s clock frequency 50 200 khz vref external voltage reference t a = ?40c to +85c 1.8 av cc v v in input voltage gnd v ref v v int internal voltage reference 1.0 1.1 1.2 v r ain analog input resistance 100 m
192 9137e?rke?12/10 atmel ATA5771/73/74 table 8-6. adc characteristics, dif ferential channels, t a = ?40c to +85c, unless otherwise noted symbol parameter condition min typ max units tue resolution differential conversion, gain = 1x bipolar mode only t a = ?40c to +85c, v cc = 1.8v to 3.6v 8bits absolute accuracy (including inl, dnl, quantization error, gain and offset error) gain = 1x, v cc = 1.8v, v ref =1.3v, adc clock = 125khz t a = ?40c to +85c, 1.6 5.0 lsb inl integral non-linearity (inl) gain = 1x, v cc = 1.8v, v ref = 1.3v, adc clock = 125khz t a = ?40c to +85c, 0.7 2.5 lsb dnl differential non-linearity (dnl) gain = 1x, v cc = 1.8v, v ref = 1.3v, adc clock = 125khz t a = ?40c to +85c, 0.3 1.0 lsb gain error gain = 1x, v cc = 1.8v, v ref = 1.3v, adc clock = 125khz t a = ?40c to +85c ?7.0 +1.50 +7.0 lsb offset error gain = 1x, v cc = 1.8v. v ref = 1.3v, adc clock = 125khz t a = ?40c to +85c ?4.0 0.0 +4.0 lsb clock frequency 50 200 khz conversion time 65 260 s v ref reference voltage t a = ?40c to +85c, v cc = 1.8v to 3.6v 1.30 avcc ? 0.5 v v in input voltage gnd avcc v v diff input differential voltage ?v ref /gain v ref /gain v
193 9137e?rke?12/10 atmel ATA5771/73/74 8.3.6 serial programming characteristics figure 8-3. serial programming timing figure 8-4. serial programming waveforms note: 1. 2 t clcl for f ck < 12mhz, 3 t clcl for f ck >= 12mhz table 8-7. serial programming characteristics, t a = ?40c to +85c, v cc = 2v - 3.6v (unless otherwise noted) symbol parameter min typ max units 1/t clcl oscillator frequency (atmel attiny44vv) 0 4 mhz t clcl oscillator period (atmel attiny44vv) 250 ns t shsl sck pulse width high 2 t clcl* ns t slsh sck pulse width low 2 t clcl* ns t ovsh mosi setup to sck high t clcl ns t shox mosi hold after sck high 2 t clcl ns t sliv sck low to miso valid tbd tbd tbd ns mosi miso sck t ovsh t shsl t slsh t shox t sliv msb msb lsb lsb serial clock input (sck) serial data input (mosi) (miso) sample serial data output
194 9137e?rke?12/10 atmel ATA5771/73/74 8.3.7 high-voltage serial programming characteristics figure 8-5. high-voltage serial programming timing table 8-8. high-voltage serial programming characteristics t a = 25c 10%, v cc = 5.0v 10% (unless otherwise noted) symbol parameter min typ max units t shsl sci (pb0) pulse width high 110 ns t slsh sci (pb0) pulse width low 110 ns t ivsh sdi (pa6), sii (pb1) valid to sci (pb0) high 50 ns t shix sdi (pa6), sii (pb1) hold after sci (pb0) high 50 ns t shov sci (pb0) high to sdo (pa4) valid 16 ns t wlwh_pfb wait after instr. 3 for write fuse bits 2.5 ms ck cc
195 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8 typical characteristics ? preliminary data the data contained in this section is largely based on simulations and characterization of sim- ilar devices in the same process and design methods. thus, the data should be treated as indications of how th e part will behave. the following charts show typical behavior. these figures are not tested during manufacturing. all current consumption measurements are performed with all i/o pins configured as inputs and with internal pull-ups enabled. a sine wave generator with rail-to-rail output is used as clock source. the power consumption in power-down mode is independent of clock selection. the current consumption is a function of several factors such as: operating voltage, operating frequency, loading of i/o pins, switching rate of i/o pins, code executed and ambient tempera- ture. the dominating factors are operating voltage and frequency. the current drawn from capacitive loaded pins may be estimated (for one pin) as c l * v cc *f where c l = load capacitance, v cc = operating voltage and f = average switching frequency of i/o pin. the parts are characterized at frequencies higher than test limits. parts are not guaranteed to function properly at frequencies higher than the ordering code indicates. the difference between current consumptio n in power-down mode with watchdog timer enabled and power-down mode with watchdog timer disabled represents the differential cur- rent drawn by the watchdog timer. 8.3.8.1 active supply current figure 8-6. active supply current vs. low frequency (0.1 - 1.0mhz) - temp. = 25c active s up p ly curre nt vs . lo w f re q ue ncy 0.1 - 1.0 mhz - temperature = 25?c 5.5 v 5.0 v 4.5 v 3.3 v 3.0 v 2.7 v 0 0.2 0.4 0.6 0.8 1 1.2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 frequency (mhz) i cc (ma)
196 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-7. active supply current vs. frequency (1 - 20mhz) - temp. = 25c figure 8-8. active supply current vs. v cc (internal rc o scillator, 8mhz) active s up p ly curre nt vs . f re q ue ncy 1 - 20 mhz - temperature = 25?c 5.5 v 5.0 v 4.5 v 3.3 v 3.0 v 2.7 v 0 5 10 15 20 25 0 2 4 6 8 10 12 14 16 18 20 frequency (mhz) i cc (ma) active s up p ly curre nt vs . v cc internal rc oscillator, 8 mhz 125 ?c 85 ?c 25 ?c -45 ?c 0 1 2 3 4 5 6 7 2.53 3.54 4.55 5.5 v cc (v) i cc (ma)
197 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-9. active supply current vs. v cc (internal rc o scillator, 1mhz) figure 8-10. active supply current vs. v cc (internal rc o scillator, 128khz) active supply current vs. v cc internal rc oscillator, 1mhz 125 ?c 85 ?c 25 ?c -40 ?c 0 0.2 0.4 0.6 0.8 1 1.2 1.4 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ma) active s up p ly curre nt vs . v cc internal rc os cillator, 1 2 8 khz 125 ?c 85 ?c 25 ?c -40 ?c 0 0.04 0.08 0.12 0.16 0.2 2.53 3.54 4.55 5.5 v cc (v) i cc (ma)
198 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.2 idle supply current figure 8-11. idle supply current vs. v cc (internal rc o scillator, 8mhz) figure 8-12. idle supply current vs. v cc (internal rc o scillator, 1mhz) idle supply current vs. v cc internal rc oscillator, 8 mhz 125 ?c 85 ?c 25 ?c -40 ?c 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.53 3.54 4.55 5.5 v cc (v) i cc (ma) idle supply current vs. v cc internal rc oscillator, 1 mhz 125 ?c 85 ?c 25 ?c -40 ?c 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 2.53 3.54 4.55 5.5 v cc (v) i cc (ma)
199 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-13. idle supply current vs. v cc (internal rc o scillator, 8mhz) 8.3.8.3 supply current of io modules the tables and formulas below can be used to calculate the additional current consumption for the different i/o modules in active and idle mode. the enabling or disabling of the i/o modules are controlled by the power reduction register. see section 4.10.6 ?power reduction regis- ter? on page 42 for details. idle supply current vs. v cc internal rc os cillator, 1 2 8 khz 125 ?c 85 ?c 25 ?c -40 ?c 0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ma) table 8-9. additional current consumption for the different i/o modules (absolute values) prr bit typical numbers v cc = 2v, f = 1 mhz v cc = 3v, f = 4 mhz prtim1 6.6 ua 26 ua prtim0 8.7 ua 35 ua prusi 5.5 ua 22 ua pradc 22 ua 87 ua
200 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.4 power-down supply current figure 8-14. power-down supply current vs. v cc (watchdog timer disabled) figure 8-15. power-down supply current vs. v cc (watchdog timer enabled) p ower-down s up p ly current vs . v cc watchdog timer dis abled 125 ?c 85 ?c 25 ?c -45 ?c 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 2.53 3.54 4.55 5.5 v cc (v) i cc (ua) p ower-down s up p ly current vs . v cc watchdog timer enabled 125 ?c 85 ?c 25 ?c -45 ?c 0 1 2 3 4 5 6 7 8 9 10 2.53 3.54 4.55 5.5 v cc (v) i cc (ua)
201 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.5 pin pull-up figure 8-16. i/o pin pull-up resistor current vs. input voltage (v cc = 2.7v) figure 8-17. reset pull-up resistor curr ent vs. reset pin voltage (v cc = 2.7v) i/ o p in p ull-up re s is to r curre nt vs . inp ut vo ltag e v cc = 2.7v 125 ?c 85 ?c 25 ?c -45 ?c 0 10 20 30 40 50 60 70 80 90 0 0.5 1 1.5 2 2.5 3 v op (v) i op (ua) reset pull-up resistor current vs. reset pin voltage vcc = 2.7v 125 ?c -40 ?c 0 10 20 30 40 50 60 0 0.5 1 1.5 2 2.5 3 v res et (v) i res et (ua)
202 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.6 pin driver strength figure 8-18. i/o pin output voltage vs. sink current (v cc = 3v) figure 8-19. i/o pin output voltage vs. source current (v cc = 3v) i/o p in outp ut voltage vs . s ink curre nt low power pins @ vc c = 3v 125 ?c 85 ?c 25 ?c -40 ?c 0 0.01 0.02 0.03 0.04 0.05 0.06 0 2 4 6 8 101214161820 i ol (ma) v ol (v) i/o p in outp ut voltage vs . s ource curre nt low power pins @ vc c = 3v 125 ?c 85 ?c 25 ?c -45 ?c 1.5 2 2.5 3 3.5 0 2 4 6 8 10 12 14 16 18 20 i oh (ma) v oh (v)
203 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.7 pin threshold and hysteresis figure 8-20. i/o pin input threshold voltage vs. v cc (v ih , io pin read as ?1?) figure 8-21. i/o pin input threshold voltage vs. v cc (v il , io pin read as ?0?) i/ o p in inp ut thre s ho ld vo ltag e vs . v cc vih, io pin read as '1 ' 125 ?c 85 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 3 3.5 2.5 3 3.5 4 4.5 5 5.5 v cc (v) thres hold (v) i/ o p in inp ut thre s ho ld vo ltag e vs . v cc vil, io pin read as '0' 125 ?c 85 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 2.53 3.54 4.55 5.5 v cc (v) thres hold (v)
204 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-22. i/o pin input hysteresis vs. v cc figure 8-23. reset input threshold voltage vs. v cc (v ih , io pin threshold as ?1?) i/ o p in inp ut hys te r e s is vs . v cc 125 ?c 85 ?c -20 ?c -40 ?c 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 2.53 3.54 4.55 5.5 v cc (v) in p u t hy s te re s is (m v) re s e t p in as i/ o thre s ho ld vo ltag e vs . v cc vih, res et read as '1' 125 ?c 85 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 3 2.5 3 3.5 4 4.5 5 5.5 v cc (v) thres hold (v)
205 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-24. reset input threshold voltage vs. v cc (v il , io pin read as ?0?) figure 8-25. reset pin input hysteresis vs. v cc reset pin as i/o threshold voltage vs. v cc vil, reset read as '0' 125 ?c 85 ?c 25 ?c -45 ?c 0 0.5 1 1.5 2 2.5 3 2.5 3 3.5 4 4.5 5 5.5 v cc (v) thres hold (v) re s e t p in inp ut hys te re s is vs . v cc 125 ?c 85 ?c 25 ?c -40 ?c 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2.5 3 3.5 4 4.5 5 5.5 v cc (v) input hysteresis (mv)
206 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.8 bod threshold and analog comparator offset figure 8-26. bod threshold vs, temperature (bodlevel is 2.7v) figure 8-27. bod threshold vs. temperature (bodlevel is 1.8v) bandgap voltage vs . te mp e rature bod = 2.7v 1 0 2.64 2.66 2.68 2.7 2.72 2.74 2.76 2.78 -40-30-20-100 102030405060708090100110120 temperature (c) thres hold (v) bandgap voltage vs . te mp e rature bod = 1.8v 1 0 1.78 1.79 1.8 1.81 1.82 1.83 1.84 1.85 -40-30-20-100 102030405060708090100110120 temperature (c) thres hold (v)
207 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.9 internal oscillator speed figure 8-28. watchdog oscillato r frequency vs. v cc figure 8-29. calibrated 8 mhz rc osc illator frequency vs. v cc w atchdo g o s cillato r f re q ue ncy vs . o p e rating vo ltag e 125 ?c 85 ?c 25 ?c -40 ?c 104 106 108 110 112 114 116 118 120 122 124 2.5 3 3.5 4 4.5 5 5.5 v cc (v) f rc (khz) calibrate d 8 . 0 mhz rc o s cillato r f re q ue ncy vs . o p e rating vo ltag e 6 6.5 7 7.5 8 8.5 9 2.5 3 3.5 4 4.5 5 5.5 v cc (v) f rc (mhz) -40 ?c 25 ?c 85 ?c 125 ?c
208 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-30. calibrated 8 mhz rc oscillato r frequency vs. temperature figure 8-31. calibrated 8 mhz rc oscillator frequency vs, osccal value calibrate d 8.0mhz rc os cillator fre que ncy vs . te mp e rature 5.0 v 3.0 v 7.7 7.8 7.9 8 8.1 8.2 8.3 8.4 -40-30-20-100 102030405060708090100110120 te mp e ra tu re f rc (mhz) calibrated 8.0mhz rc os cillator frequency vs . os ccal value (vcc=3v) 125 ?c 85 ?c 25 ?c -40 ?c 0 2 4 6 8 10 12 14 16 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 osccal (x1) f rc (mhz)
209 9137e?rke?12/10 atmel ATA5771/73/74 8.3.8.10 current consumption of peripheral units figure 8-32. adc current vs. v c c figure 8-33. analog comparator current vs. v cc adc current vs . v cc 4.0 mhz frequency -40 ?c 25 ?c 85 ?c 125 ?c 0 100 200 300 400 500 600 700 2.53 3.54 4.55 5.5 v cc (v) i cc (ua) adc current vs . v cc 4.0 mhz frequency -40 ?c 25 ?c 85 ?c 125 ?c 0 10 20 30 40 50 60 70 80 90 100 2.53 3.54 4.55 5.5 v cc (v) i cc (ua)
210 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-34. programming current vs. v cc figure 8-35. brownout detector current vs. v cc i/o module current vs . vcc 4.0 mhz frequency 25 ?c 0 2000 4000 6000 8000 10000 12000 2.53.54.55.5 v cc (v) i cc (ua) brownout de te ctor curre nt vs . v cc bo d le v e l = 1 . 8 v 125 ?c 85 ?c 25 ?c -40 ?c 0 2 4 6 8 10 12 14 16 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 v cc (v) i cc (ua)
211 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-36. watchdog timer current vs. v cc 8.3.8.11 current consumption in reset and re set pulse width figure 8-37. reset supply current vs. v cc (0.1 - 1.0mhz, excluding current through the reset pull-up) watchdog timer current vs v cc 125 ?c 85 ?c 25 ?c -40 ?c 0 5 10 15 20 25 30 2.53 3.54 4.55 5.5 v cc (v) i cc (ua) re s e t s up p ly curre nt vs . v cc excluding current through the res et pullup 5.5 v 5.0 v 4.5 v 3.3 v 3.0 v 2.7 v 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 frequency (mhz) i cc (ma)
212 9137e?rke?12/10 atmel ATA5771/73/74 figure 8-38. reset supply current vs. v cc (1 - 20mhz, excluding current through the reset pull-up) figure 8-39. minimum reset pulse width vs. v cc re s e t s up p ly curre nt vs . v cc excluding current through the res et pullup 5.5 v 5.0 v 4.5 v 3.6 v 3.3 v 3.0 v 2.7 v 0 0.5 1 1.5 2 2.5 3 0 2 4 6 8 10 12 14 16 18 20 frequency (mhz) i cc (ma) minimum re s e t p uls e width vs . v cc 125 ?c 85 ?c 25 ?c -40 ?c 0 200 400 600 800 1000 1200 2.5 3 3.5 4 4.5 5 5.5 v cc (v) p u ls e w id th ( n s )
213 9137e?rke?12/10 atmel ATA5771/73/74 9. appendix 9.1 register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page 0x3f (0x5f) sreg i t h s v n z c page 16 0x3e (0x5e) sph ? ? ? ? ? ? sp9 sp8 page 18 0x3d (0x5d) spl sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 page 18 0x3c (0x5c) ocr0b timer/counter0 ? output compare register b page 92 0x3b (0x5b) gimsk ? int0 pcie1 pcie0 ? ? ? ? page 58 0x3a (0x5a gifr ? intf0 pcif1 pcif0 ? ? ? ? page 59 0x39 (0x59) timsk0 ? ? ? ? ? ocie0b ocie0a toie0 page 93 0x38 (0x58) tifr0 ? ? ? ? ocf0b ocf0a tov0 page 93 0x37 (0x57) spmcsr ? ? ? ctpb rflb pgwrt pgers spmen page 164 0x36 (0x56) ocr0a timer/counter0 ? output compare register a page 92 0x35 (0x55) mcucr ?pudsesm1sm0 ? isc01 isc00 page 58 0x34 (0x54) mcusr ? ? ? ? wdrf borf extrf porf page 51 0x33 (0x53) tccr0b foc0a foc0b ? ? wgm02 cs02 cs01 cs00 page 91 0x32 (0x52) tcnt0 timer/counter0 page 92 0x31 (0x51) osccalcal7cal6cal5cal4cal3cal2cal1cal0 page 39 0x30 (0x50) tccr0a com0a1 com0a0 com0b1 com0b0 ? wgm01 wgm00 page 88 0x2f (0x4f) tccr1a com1a1 com1a0 com1b1 com1b0 ? wgm11 wgm10 page 116 0x2e (0x4e) tccr1b icnc1 ices1 ? wgm13 wgm12 cs12 cs11 cs10 page 118 0x2d (0x4d) tcnt1h timer/counter1 ? counter register high byte page 120 0x2c (0x4c) tcnt1l timer/counter1 ? counter register low byte page 120 0x2b (0x4b) ocr1ah timer/counter1 ? compare register a high byte page 120 0x2a (0x4a) ocr1al timer/counter1 ? compare register a low byte page 120 0x29 (0x49) ocr1bh timer/counter1 ? compare register b high byte page 120 0x28 (0x48) ocr1bl timer/counter1 ? compare register b low byte page 120 0x27 (0x47) dwdr dwdr[7:0] page 160 0x26 (0x46) clkpr clkpce ? ? ? clkps3 clkps2 clkps1 clkps0 page 39 0x25 (0x45) icr1h timer/counter1 - input capture register high byte page 121 0x24 (0x44) icr1l timer/counter1 - input capture register low byte page 121 0x23 (0x43) gtccr tsm ? ? ? ? ? ? psr10 page 124 0x22 (0x42) tccr1c foc1a foc1b ? ? ? ? ? ? page 119 0x21 (0x41) wdtcsr wdif wdie wdp3 wdce wde wdp2 wdp1 wdp0 page 52 0x20 (0x40) pcmsk1 ? ? ? ? pcint11 pcint10 pcint9 pcint8 page 59 0x1f (0x3f) eearh ? ? ? ? ? ? ? eear8 page 29 0x1e (0x3e) eearl eear7 eear6 eear5 eear4 eear3 eear2 eear1 eear0 page 29 0x1d (0x3d) eedr eeprom data register page 29 0x1c (0x3c) eecr ? ? eepm1 eepm0 eerie eempe eepe eere page 29 0x1b (0x3b) porta porta7 porta6 porta5 p orta4 porta3 porta2 porta1 porta0 page 74 0x1a (0x3a) ddra dda7 dda6 dda5 dda4 dda3 dda2 dda1 dda0 page 75 0x19 (0x39) pina pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 page 75 0x18 (0x38) portb ? ? ? ? portb3 portb2 portb1 portb0 page 75 0x17 (0x37) ddrb ? ? ? ? ddb3 ddb2 ddb1 ddb0 page 75 0x16 (0x36) pinb ? ? ? ? pinb3 pinb2 pinb1 pinb0 page 75 0x15 (0x35) gpior2 general purpose i/o register 2 page 31 0x14 (0x34) gpior1 general purpose i/o register 1 page 31 0x13 (0x33) gpior0 general purpose i/o register 0 page 31 0x12 (0x32) pcmsk0 pcint7 pcint6 pcint5 pcint4 pcint3 pcint2 pcint1 pcint0 page 60 0x11 (0x31)) reserved ? 0x10 (0x30) usibr usi buffer register page 133 0x0f (0x2f) usidr usi data register page 133 0x0e (0x2e) usisr usisif usioif usipf usidc usicnt3 usicnt2 usi cnt1 usicnt0 page 133 0x0d (0x2d) usicr usisie usioie usiwm1 usiwm0 usics1 usics0 usiclk usitc page 134 0x0c (0x2c) timsk1 ? ?icie1 ? ? ocie1b ocie1a toie1 page 121 notes: 1. for compatibility with future device s, reserved bits should be written to zero if accessed. reserved i/o memory address es should never be written. 2. i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using the sbi and cbi instructions. in these registers, the value of single bits can be checked by using the sbis and sbic instructions. 3. some of the status flags are clear ed by writing a logical one to them . note that, unlike most other avr ? s, the cbi and sbi instructions will only operation the specified bit, and can therefore be used on registers containing such status flags. the cbi and sbi instructions work with registers 0x00 to 0x1f only
214 9137e?rke?12/10 atmel ATA5771/73/74 0x0b (0x2b) tifr1 ? ?icf1 ? ? ocf1b ocf1a tov1 page 122 0x0a (0x2a) reserved ? 0x09 (0x29) reserved ? 0x08 (0x28) acsr acd acbg aco aci acie acic acis1 acis0 page 138 0x07 (0x27) admux refs1 refs0 mux5 mux4 mux3 mux2 mux1 mux0 page 152 0x06 (0x26) adcsra aden adsc adate adif adie adps2 adps1 adps0 page 155 0x05 (0x25) adch adc data register high byte page 156 0x04 (0x24) adcl adc data register low byte page 156 0x03 (0x23) adcsrb bin acme ?adlar ? adts2 adts1 adts0 page 138 0x02 (0x22) reserved ? 0x01 (0x21) didr0 adc7d adc6d adc5d adc4 d adc3d adc2d adc1d adc0d page 139,page 158 0x00 (0x20) prr ? ? ? ? prtim1 prtim0 prusi pradc page 44 9.1 register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page notes: 1. for compatibility with future device s, reserved bits should be written to zero if accessed. reserved i/o memory address es should never be written. 2. i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using the sbi and cbi instructions. in these registers, the value of single bits can be checked by using the sbis and sbic instructions. 3. some of the status flags are clear ed by writing a logical one to them . note that, unlike most other avr ? s, the cbi and sbi instructions will only operation the specified bit, and can therefore be used on registers containing such status flags. the cbi and sbi instructions work with registers 0x00 to 0x1f only 9.2 instruction set summary mnemonics operands description operation flags #clocks arithmetic and logic instructions add rd, rr add two registers rd rd + rr z,c,n,v,h 1 adc rd, rr add with carry two registers rd rd + rr + c z,c,n,v,h 1 adiw rdl,k add immediate to word rdh:rdl rdh:rdl + k z,c,n,v,s 2 sub rd, rr subtract two registers rd rd - rr z,c,n,v,h 1 subi rd, k subtract constant from register rd rd - k z,c,n,v,h 1 sbc rd, rr subtract with carry two registers rd rd - rr - c z,c,n,v,h 1 sbci rd, k subtract with carry constant from reg. rd rd - k - c z,c,n,v,h 1 sbiw rdl,k subtract immediate from word rdh:rdl rdh:rdl - k z,c,n,v,s 2 and rd, rr logical and registers rd rd ? rr z,n,v 1 andi rd, k logical and register and constant rd rd ? k z,n,v 1 or rd, rr logical or registers rd rd v rr z,n,v 1 ori rd, k logical or register and constant rd rd v k z,n,v 1 eor rd, rr exclusive or registers rd rd rr z,n,v 1 com rd one?s complement rd 0xff ? rd z,c,n,v 1 neg rd two?s complement rd 0x00 ? rd z,c,n,v,h 1 sbr rd,k set bit(s) in register rd rd v k z,n,v 1 cbr rd,k clear bit(s) in register rd rd ? (0xff - k) z,n,v 1 inc rd increment rd rd + 1 z,n,v 1 dec rd decrement rd rd ? 1 z,n,v 1 tst rd test for zero or minus rd rd ? rd z,n,v 1 clr rd clear register rd rd rd z,n,v 1 ser rd set register rd 0xff none 1 branch instructions rjmp k relative jump pc pc + k + 1 none 2 ijmp indirect jump to (z) pc z none 2 rcall k relative subroutine call pc pc + k + 1 none 3 icall indirect call to (z) pc znone3 ret subroutine return pc stack none 4 reti interrupt return pc stack i 4 cpse rd,rr compare, skip if equal if (rd = rr) pc pc + 2 or 3 none 1/2/3 cp rd,rr compare rd ? rr z, n,v,c,h 1 cpc rd,rr compare with carry rd ? rr ? c z, n,v,c,h 1 cpi rd,k compare register with immediate rd ? k z, n,v,c,h 1 sbrc rr, b skip if bit in register cleared if (rr(b)=0) pc pc + 2 or 3 none 1/2/3 sbrs rr, b skip if bit in register is set if (rr(b)=1) pc pc + 2 or 3 none 1/2/3
215 9137e?rke?12/10 atmel ATA5771/73/74 sbic p, b skip if bit in i/o regi ster cleared if (p(b)=0) pc pc + 2 or 3 none 1/2/3 sbis p, b skip if bit in i/o register is set if (p(b)=1) pc pc + 2 or 3 none 1/2/3 brbs s, k branch if status flag set if (sreg(s) = 1) then pc pc+k + 1 none 1/2 brbc s, k branch if status flag cleared if (sreg(s) = 0) then pc pc+k + 1 none 1/2 breq k branch if equal if (z = 1) then pc pc + k + 1 none 1/2 brne k branch if not equal if (z = 0) then pc pc + k + 1 none 1/2 brcs k branch if carry set if (c = 1) then pc pc + k + 1 none 1/2 brcc k branch if carry cleared if (c = 0) then pc pc + k + 1 none 1/2 brsh k branch if same or higher if (c = 0) then pc pc + k + 1 none 1/2 brlo k branch if lower if (c = 1) then pc pc + k + 1 none 1/2 brmi k branch if minus if (n = 1) then pc pc + k + 1 none 1/2 brpl k branch if plus if (n = 0) then pc pc + k + 1 none 1/2 brge k branch if greater or equal, signed if (n v= 0) then pc pc + k + 1 none 1/2 brlt k branch if less than zero, signed if (n v= 1) then pc pc + k + 1 none 1/2 brhs k branch if half carry flag set if (h = 1) then pc pc + k + 1 none 1/2 brhc k branch if half carry flag cleared if (h = 0) then pc pc + k + 1 none 1/2 brts k branch if t flag set if (t = 1) then pc pc + k + 1 none 1/2 brtc k branch if t flag cleared if (t = 0) then pc pc + k + 1 none 1/2 brvs k branch if overflow flag is set if (v = 1) then pc pc + k + 1 none 1/2 brvc k branch if overflow flag is cleared if (v = 0) then pc pc + k + 1 none 1/2 brie k branch if interrupt enabled if ( i = 1) then pc pc + k + 1 none 1/2 brid k branch if interrupt disabled if ( i = 0) then pc pc + k + 1 none 1/2 bit and bit-test instructions sbi p,b set bit in i/o register i/o(p,b) 1none2 cbi p,b clear bit in i/o register i/o(p,b) 0none2 lsl rd logical shift left rd(n+1) rd(n), rd(0) 0 z,c,n,v 1 lsr rd logical shift right rd(n) rd(n+1), rd(7) 0 z,c,n,v 1 rol rd rotate left through carry rd(0) c,rd(n+1) rd(n),c rd(7) z,c,n,v 1 ror rd rotate right through carry rd(7) c,rd(n) rd(n+1),c rd(0) z,c,n,v 1 asr rd arithmetic shift right rd(n) rd(n+1), n=0..6 z,c,n,v 1 swap rd swap nibbles rd(3..0) rd(7..4),rd(7..4) rd(3..0) none 1 bset s flag set sreg(s) 1 sreg(s) 1 bclr s flag clear sreg(s) 0 sreg(s) 1 bst rr, b bit store from register to t t rr(b) t 1 bld rd, b bit load from t to register rd(b) tnone1 sec set carry c 1c1 clc clear carry c 0 c 1 sen set negative flag n 1n1 cln clear negative flag n 0 n 1 sez set zero flag z 1z1 clz clear zero flag z 0 z 1 sei global interrupt enable i 1i1 cli global interrupt disable i 0 i 1 ses set signed test flag s 1s1 cls clear signed test flag s 0 s 1 sev set twos complement overflow. v 1v1 clv clear twos complement overflow v 0 v 1 set set t in sreg t 1t1 clt clear t in sreg t 0 t 1 seh set half carry flag in sreg h 1h1 clh clear half carry flag in sreg h 0 h 1 data transfer instructions mov rd, rr move between registers rd rr none 1 movw rd, rr copy register word rd+1:rd rr+1:rr none 1 ldi rd, k load immediate rd knone1 ld rd, x load indirect rd (x) none 2 ld rd, x+ load indirect and post-inc. rd (x), x x + 1 none 2 ld rd, - x load indirect and pre-dec. x x - 1, rd (x) none 2 ld rd, y load indirect rd (y) none 2 ld rd, y+ load indirect and post-inc. rd (y), y y + 1 none 2 ld rd, - y load indirect and pre-dec. y y - 1, rd (y) none 2 ldd rd,y+q load indirect with displacement rd (y + q) none 2 ld rd, z load indirect rd (z) none 2 ld rd, z+ load indirect and post-inc. rd (z), z z+1 none 2 ld rd, -z load indirect and pre-dec. z z - 1, rd (z) none 2 9.2 instruction set summary (continued) mnemonics operands description operation flags #clocks
216 9137e?rke?12/10 atmel ATA5771/73/74 ldd rd, z+q load indirect with displacement rd (z + q) none 2 lds rd, k load direct from sram rd (k) none 2 st x, rr store indirect (x) rr none 2 st x+, rr store indirect and post-inc. (x) rr, x x + 1 none 2 st - x, rr store indirect and pre-dec. x x - 1, (x) rr none 2 st y, rr store indirect (y) rr none 2 st y+, rr store indirect and post-inc. (y) rr, y y + 1 none 2 st - y, rr store indirect and pre-dec. y y - 1, (y) rr none 2 std y+q,rr store indirect with displacement (y + q) rr none 2 st z, rr store indirect (z) rr none 2 st z+, rr store indirect and post-inc. (z) rr, z z + 1 none 2 st -z, rr store indirect and pre-dec. z z - 1, (z) rr none 2 std z+q,rr store indirect with displacement (z + q) rr none 2 sts k, rr store direct to sram (k) rr none 2 lpm load program memory r0 (z) none 3 lpm rd, z load program memory rd (z) none 3 lpm rd, z+ load program memory and post-inc rd (z), z z+1 none 3 spm store program memory (z) r1:r0 none in rd, p in port rd pnone1 out p, rr out port p rr none 1 push rr push register on stack stack rr none 2 pop rd pop register from stack rd stack none 2 mcu control instructions nop no operation none 1 sleep sleep (see specific descr. for sleep function) none 1 wdr watchdog reset (see specific descr. for wdr/timer) none 1 break break for on-chip debug only none n/a 9.2 instruction set summary (continued) mnemonics operands description operation flags #clocks
217 9137e?rke?12/10 atmel ATA5771/73/74 11. package information 10. ordering information extended type number package remarks ATA5771-pxqw qfn24 5mm x 5mm microcontroller with uhf tx for 868mhz to 928mhz, taped and reeled ata5773-pxqw qfn24 5mm x 5mm microcontroller with uhf tx for 310mhz to 350mhz, taped and reeled ata5774-pxqw qfn24 5mm x 5mm microcontroller with uhf tx for 429mhz to 439mhz, taped and reeled specifications according to din technical drawings 0.3 0.4 0.9 0.1 not indicated tolerances 0.05 0.65 nom. 0.05 -0.05 +0 12 7 19 24 13 18 6 24 1 6 1 issue: 1; 15.11.05 drawing-no.: 6.543-5122.01-4 5 3.25 3.6 dimensions in mm package: qfn 24 - 5 x 5 exposed pad 3.6 x 3.6 (acc. jedec outline no. mo-220)
218 9137e?rke?12/10 atmel ATA5771/73/74 12. revision history please note that the following page numbers referred to in this section refer to the specific revision mentioned, not to this document. revision no. history 9137e-rke-12/10 ? section 8.1 ?the general current co nsumption characteristics for key fob application? on page 186 changed ? section 8.2 ?rf transmitter block? on pages 186 to 187 changed ? section 8.3 ?microcontroller block? on pages 188 to 212 changed 9137d-rke-09/10 ? all pages: attiny24 and attiny84 deleted ? all pages: flash size 2k and 8k deleted ? figures 4-7 and 4-8 changed ? text under headings 4.2, 4.8.1, 4.8. 2, 4.8.3, 4.8.5.1 and 4.8.5.2 changed ? section 8.1 ?the general current co nsumption characteristics for key fob application? on page 186 changed ? table 8-1 ?calibration accuracy of internal rc oscillator? on page 189 changed ? table 8-4 ?bodlevel fuse coding? on page 190 changed
atmel corporation 2325 orchard parkway san jose, ca 95131 usa tel: (+1)(408) 441-0311 fax: (+1)(408) 487-2600 atmel asia limited unit 01-5 & 16, 19/f bea tower, millennium city 5 418 kwun tong road kwun tong, kowloon hong kong tel: (+852) 2245-6100 fax: (+852) 2722-1369 atmel munich gmbh business campus parkring 4 d-85748 garching b. munich germany tel: (+49) 89-31970-0 fax: (+49) 89-3194621 atmel japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel: (+81) (3) 3523-3551 fax: (+81) (3) 3523-7581 ? 2010 atmel corporation. all rights reserved. / rev.: 9137e?rke?12/10 atmel ? , atmel logo and combinations thereof, avr ? , avr studio ? and others are registered trademarks or tradema rks of atmel corporation or its subsid- iaries. other terms and product names may be trademarks of others. disclaimer: the information in this document is provided in con nection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellec- tual property right is granted by this document or in connection with the sale of atmel products. except as set forth in the at mel terms and conditions of sales located on the atmel website, atmel assumes no liability whatsoever and disclaims any express, implied or statutory warranty relating to its products including, but not limited to, the implied warranty of merchantability, fitness for a particu - lar purpose, or non-infringement. in no event shall atmel be liable for any direct, indirect, consequential, punitive, special or incidental damages (including, without limitation, damages for lo ss and profits, business interruption, or loss of information) arising out of the use or inabil ity to use this document, even if atmel has been advised of the possibility of such damages. at mel makes no representations or warranties with respect to the accura cy or completeness of the contents of this document and reserv es the right to make changes to specifications and products descriptions at any time without not ice. atmel does not make any commitment to update the informati on contained herein. unless specif- ically provided otherwise, atmel produc ts are not suitable for, and shall not be used in, automotive applications. atmel produc ts are not intended, authorized, or war- ranted for use as components in applicatio ns intended to support or sustain life.


▲Up To Search▲   

 
Price & Availability of ATA5771

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X